gbranden pushed a commit to branch master
in repository groff.

commit 7c34cb99ee89e0ab490558d0b40a66ae6a39c5c7
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu May 15 11:03:39 2025 -0500

    [troff]: Warn if cflags request arg out of range.
    
    * src/roff/troff/charinfo.h (class charinfo): Add `CFLAGS_MAX`
      enumeration constant.
    
    * src/roff/troff/input.cpp (set_character_flags): Throw warning in
      category "range" and ignore request if first argument is a valid
      integer but out of range.
---
 ChangeLog                 | 11 +++++++++++
 src/roff/troff/charinfo.h |  3 ++-
 src/roff/troff/input.cpp  |  7 +++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 950a1e65e..56e01838c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2025-05-15  G. Branden Robinson <[email protected]>
+
+       [troff]: Warn on out-of-range `cflags` request argument.
+
+       * src/roff/troff/charinfo.h (class charinfo): Add `CFLAGS_MAX`
+       enumeration constant.
+
+       * src/roff/troff/input.cpp (set_character_flags): Throw warning
+       in category "range" and ignore request if first argument is a
+       valid integer but out of range.
+
 2025-05-15  G. Branden Robinson <[email protected]>
 
        [troff]: Fix code style nit; use unsigned integer literals when
diff --git a/src/roff/troff/charinfo.h b/src/roff/troff/charinfo.h
index 9a84ab828..b07248c52 100644
--- a/src/roff/troff/charinfo.h
+++ b/src/roff/troff/charinfo.h
@@ -58,7 +58,8 @@ public:
     IGNORES_SURROUNDING_HYPHENATION_CODES = 0x40,
     PROHIBITS_BREAK_BEFORE = 0x80,
     PROHIBITS_BREAK_AFTER = 0x100,
-    IS_INTERWORD_SPACE = 0x200
+    IS_INTERWORD_SPACE = 0x200,
+    CFLAGS_MAX = 0x2FF
   };
   enum {
     TRANSLATE_NONE,
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index bcdefaf1b..78e9e4385 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -8058,6 +8058,13 @@ static void set_character_flags()
   }
   int flags;
   if (get_integer(&flags)) {
+    if ((flags < 0) || (flags > charinfo::CFLAGS_MAX)) {
+      warning(WARN_RANGE, "character flags must be in range 0..%1",
+             charinfo::CFLAGS_MAX);
+      skip_line();
+      return;
+    }
+    // TODO: Check for contradictory character flags.
     if (!has_arg()) {
       warning(WARN_MISSING, "character flags configuration request"
              " expects one or more characters to configure");

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to