gbranden pushed a commit to branch master
in repository groff.
commit 1842763b73bc51dbb23c7bc2c4b313427ddfcb55
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Apr 11 06:24:39 2026 -0500
src/libs/libgroff/symbol.cpp: Make code hygienic.
* src/libs/libgroff/symbol.cpp (symbol::json_length): Strengthen
assertion, since we don't permit use of C0 controls in identifiers;
see Savannah #67734. Use preprocessor to disable unused code.
(symbol::json_extract): Add assertion, since we don't permit empty
identifiers. Use preprocessor to disable unused code.
---
ChangeLog | 9 +++++++++
src/libs/libgroff/symbol.cpp | 11 ++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 8e4f45105..27094111b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-04-11 G. Branden Robinson <[email protected]>
+
+ * src/libs/libgroff/symbol.cpp (symbol::json_length): Strengthen
+ assertion, since we don't permit use of C0 controls in
+ identifiers; see Savannah #67734. Use preprocessor to disable
+ unused code.
+ (symbol::json_extract): Add assertion, since we don't permit
+ empty identifiers. Use preprocessor to disable unused code.
+
2026-04-11 G. Branden Robinson <[email protected]>
[groff]: Test unusual characters in identifiers, improving
diff --git a/src/libs/libgroff/symbol.cpp b/src/libs/libgroff/symbol.cpp
index 505912a65..54f165837 100644
--- a/src/libs/libgroff/symbol.cpp
+++ b/src/libs/libgroff/symbol.cpp
@@ -180,12 +180,16 @@ size_t symbol::json_length() const
int nextrachars = 2; // leading and trailing double quotes
for (size_t i = 0; p[i] != '\0'; i++, len++) {
ch = p[i];
- assert ((ch >= 0) && (ch <= 127));
+ assert ((ch >= 32) && (ch <= 127));
// These printable characters require escaping.
if (('"' == ch) || ('\\' == ch) || ('/' == ch))
nextrachars++;
+#if 0
else if (csprint(ch))
;
+ // We don't support C0 or C1 controls in identifiers; see Savannah
+ // #67734. In the future we plan to support Latin-1 Extension code
+ // points in multibyte UTF-8 sequences in identifiers.
else
switch (ch) {
case '\b':
@@ -198,6 +202,7 @@ size_t symbol::json_length() const
default:
nextrachars += 5;
}
+#endif
}
return (len + nextrachars);
}
@@ -213,6 +218,7 @@ const char *symbol::json_extract() const
size_t i;
char *q = static_cast<char *>(calloc((this->json_length() + 1),
sizeof (char)));
+ assert(q != 0 /* nullptr */); // We don't support empty identifiers.
if (q != 0 /* nullptr */) {
r = q;
*r++ = '"';
@@ -224,8 +230,11 @@ const char *symbol::json_extract() const
}
*r++ = '"';
}
+ // We don't support empty identifiers.
+#if 0
else
return strdup("\"\""); // so it can be free()d
+#endif
*r++ = '\0';
return q;
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit