gbranden pushed a commit to branch master
in repository groff.
commit a578d066c7c93c9d159233d88645e18c2fb51158
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Oct 25 22:56:57 2026 -0500
[troff]: Fix Savannah #68837.
* src/roff/troff/input.cpp (read_font_identifier): Replace assert(3)ion
that could be tripped by invalid characters in font identifier (or
mounting position) with skip of input line and early return. Add
assert(3)ion that the `symbol` returned by `read_identifier()` is not
`empty()`, since that appears to be impossible at present. Add
fallback conditional test for `NDEBUG` builds to return `false` if
that is the case. Since we now return early if the symbol is not
invalid and not empty, drop subsequent tests of these conditions.
Fixes <https://savannah.gnu.org/bugs/?68837>. Problem introduced by me
in commit 3dc11a61aa, 18 April.
---
ChangeLog | 17 +++++++++++++++++
src/roff/troff/node.cpp | 45 ++++++++++++++++++++++++---------------------
2 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 94f423cf4..1314d1688 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2026-10-25 G. Branden Robinson <[email protected]>
+
+ [troff]: Fix Savannah #68837.
+
+ * src/roff/troff/input.cpp (read_font_identifier): Replace
+ assert(3)ion that could be tripped by invalid characters in
+ font identifier (or mounting position) with skip of input
+ line and early return. Add assert(3)ion that the `symbol`
+ returned by `read_identifier()` is not `empty()`, since that
+ appears to be impossible at present. Add fallback conditional
+ test for `NDEBUG` builds to return `false` if that is the case.
+ Since we now return early if the symbol is not invalid and not
+ empty, drop subsequent tests of these conditions.
+
+ Fixes <https://savannah.gnu.org/bugs/?68837>. Problem
+ introduced by me in commit 3dc11a61aa, 18 April.
+
2026-10-25 G. Branden Robinson <[email protected]>
[groff]: Regression-test Savannah #68837.
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index c34275a17..a75396918 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -7056,20 +7056,25 @@ static bool read_font_identifier(font_lookup_info
*finfo)
// interpretable as an (unsigned) decimal integer. If is, we treat it
// as a mounting position. If not, we treat it as a font "name".
symbol s = read_identifier();
+ if (s.is_null()) {
+ // The identifier was garbage, like `a\&b`.
+ skip_line();
+ return false;
+ }
+ assert(!s.is_empty());
+ if (s.is_empty()) // NDEBUG
+ return false;
bool is_number = true;
- assert(!s.is_null() && !s.is_empty());
- if (!s.is_null() && !s.is_empty()) {
- const char *p = s.contents();
- assert(*p != 0 /* nullptr */);
- // Silently ignore a leading minus sign so we can issue a range
- // warning later.
- if ((csdigit(*p)) || ('-' == *p))
- p++;
- for (; (p != 0 /* nullptr */) && (*p != '\0'); p++) {
- if (!csdigit(*p)) {
- is_number = false;
- break;
- }
+ const char *p = s.contents();
+ assert(*p != 0 /* nullptr */);
+ // Silently ignore a leading minus sign so we can issue a range
+ // warning later.
+ if ((csdigit(*p)) || ('-' == *p))
+ p++;
+ for (; (p != 0 /* nullptr */) && (*p != '\0'); p++) {
+ if (!csdigit(*p)) {
+ is_number = false;
+ break;
}
}
if (is_number) {
@@ -7089,15 +7094,13 @@ static bool read_font_identifier(font_lookup_info
*finfo)
}
else {
finfo->requested_name = const_cast<char *>(s.contents());
- if (!s.is_null()) {
- int mp = mounting_position_of_font(s);
- if (mp < 0) {
- mp = next_available_font_mounting_position();
- if (mount_font_at_position(s, mp))
- finfo->position = mp;
- }
- finfo->position = curenv->get_family()->resolve(mp);
+ int mp = mounting_position_of_font(s);
+ if (mp < 0) {
+ mp = next_available_font_mounting_position();
+ if (mount_font_at_position(s, mp))
+ finfo->position = mp;
}
+ finfo->position = curenv->get_family()->resolve(mp);
}
return (finfo->position != FONT_NOT_MOUNTED);
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit