gbranden pushed a commit to branch master
in repository groff.

commit bf48529b4b71690425553072a1050b0fe52ea3a8
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Oct 18 21:50:38 2026 -0500

    [troff]: Revise `rn` input validation.
    
    * src/roff/troff/input.cpp (rename_macro): Use `has_arg()` to check for
      arguments after the first, more reliably issuing warning in category
      "missing".  Since per the previous change to this function, we have
      returned early if the `s1` symbol `is_null()`, we no longer need a
      `!s1.is_null()` condition here--that is tautologically true.  Drop the
      conditional, putting collection of second argument on main execution
      trace.  Check the second identifier for bogosity just as we checked
      the first.
    
    Before:
    $ printf '.rn\n' | ./build/test-groff -ww
    troff:<standard input>:1: warning: renaming request expects arguments [-w 
missing]
    $ printf '.rn .T\n' | ./build/test-groff -ww
    troff:<standard input>:1: warning: renaming request expects identifier of 
existing request, macro, string, or diversion as second argument [-w missing]
    $ printf '.rn .T \002\n' | ./build/test-groff -ww
    troff:<standard input>:1: error: ignoring identifier containing invalid 
character code 2
    troff:<standard input>:1: warning: renaming request expects identifier of 
existing request, macro, string, or diversion as second argument [-w missing]
    
    After:
    $ printf '.rn\n' | ./build/test-groff -ww
    troff:<standard input>:1: warning: renaming request expects arguments [-w 
missing]
    $ printf '.rn .T\n' | ./build/test-groff -ww
    troff:<standard input>:1: warning: renaming request expects two arguments 
[-w missing]
    $ printf '.rn .T \002\n' | ./build/test-groff -ww
    troff:<standard input>:1: error: ignoring identifier containing invalid 
character code 2
---
 ChangeLog                | 14 ++++++++++++++
 src/roff/troff/input.cpp | 19 +++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f05c1c3bc..0d89ec621 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2026-10-18  G. Branden Robinson <[email protected]>
+
+       [troff]: Revise `rn` input validation.
+
+       * src/roff/troff/input.cpp (rename_macro): Use `has_arg()` to
+       check for arguments after the first, more reliably issuing
+       warning in category "missing".  Since per the previous change to
+       this function, we have returned early if the `s1` symbol
+       `is_null()`, we no longer need a `!s1.is_null()` condition
+       here--that is tautologically true.  Drop the conditional,
+       putting collection of second argument on main execution trace.
+       Check the second identifier for bogosity just as we checked the
+       first.
+
 2026-10-18  G. Branden Robinson <[email protected]>
 
        [troff]: Fix Savannah #68797.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 9d107fca8..74ef058ff 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5864,15 +5864,18 @@ static void rename_macro() // .rn
     skip_line();
     return;
   }
-  if (!s1.is_null()) {
-    symbol s2 = read_identifier();
-    if (s2.is_null())
-      warning(WARN_MISSING, "renaming request expects identifier of"
-             " existing request, macro, string, or diversion as"
-             " second argument");
-    else
-      request_dictionary.rename(s1, s2);
+  if (!has_arg()) {
+    warning(WARN_MISSING, "renaming request expects two arguments");
+    skip_line();
+    return;
+  }
+  symbol s2 = read_identifier();
+  if (s2.is_null()) {
+    // The identifier was garbage, like `a\&b`.
+    skip_line();
+    return;
   }
+  request_dictionary.rename(s1, s2);
   skip_line();
 }
 

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

Reply via email to