gbranden pushed a commit to branch master
in repository groff.

commit 5f2704d64abb3d04477b1f2907eabdfec19e2925
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Sep 2 04:17:36 2024 -0500

    [troff]: Fix Savannah #66151.
    
    Update input token pointer appropriately when certain requests requiring
    arguments are invalidly invoked without them.
    
    * src/roff/troff/env.cpp (override_sizes):
    * src/roff/troff/input.cpp (while_request, pipe_output, system_request):
      Check for arguments: if none are present, throw warning in category
      "missing" and skip the remainder of the input line.
    
      (pipe_output, system_request): Add some assertions for paranoia's
      sake.
    
    Fixes <https://savannah.gnu.org/bugs/?66151>.
---
 ChangeLog                | 15 +++++++++++++++
 src/roff/troff/env.cpp   |  6 ++++++
 src/roff/troff/input.cpp | 27 +++++++++++++++++++++++++--
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index eb6a0b9d3..7f142f819 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-09-02  G. Branden Robinson <[email protected]>
+
+       [troff]: Update input token pointer appropriately when certain
+       requests requiring arguments are invalidly invoked without them.
+
+       * src/roff/troff/env.cpp (override_sizes):
+       * src/roff/troff/input.cpp (while_request, pipe_output)
+       (system_request): Check for arguments: if none are present,
+       throw warning in category "missing" and skip the remainder of
+       the input line.
+       (pipe_output, system_request): Add some assertions for
+       paranoia's sake.
+
+       Fixes <https://savannah.gnu.org/bugs/?66151>.
+
 2024-09-02  G. Branden Robinson <[email protected]>
 
        [troff]: The `kern` request now interprets arguments with
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 49ba0b726..263325701 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1325,6 +1325,12 @@ void point_size()
 
 void override_sizes()
 {
+  if (!has_arg()) {
+    warning(WARN_MISSING, "available font sizes override request"
+           " expects at least one argument");
+    skip_line();
+    return;
+  }
   int n = 16;
   int *sizes = new int[n]; // C++03: new int[n]();
   (void) memset(sizes, 0, (n * sizeof(int)));
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 0b37a0863..7fed785b9 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1890,7 +1890,10 @@ void token::skip()
     next();
 }
 
-// Specify `want_peek` if request reads the next argument in copy mode.
+// Specify `want_peek` if request reads the next argument in copy mode,
+// or otherwise must interpret it specially, as when reading a
+// conditional expression (`if`, `ie`, `while`), or expecting a
+// delimited argument (`tl`).
 bool has_arg(bool want_peek)
 {
   if (tok.is_newline())
@@ -6334,7 +6337,11 @@ static bool want_loop_break = false;
 
 static void while_request()
 {
-  // We can't use `has_arg()` here.  XXX: Figure out why.
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "while loop request expects arguments");
+    skip_line();
+    return;
+  }
   macro mac;
   bool is_char_escaped = false;
   int level = 0;
@@ -8164,6 +8171,12 @@ char *read_string()
 
 void pipe_output()
 {
+  if (!has_arg()) {
+    warning(WARN_MISSING, "device-independent output piping request"
+           " expects a system command as argument");
+    skip_line();
+    return;
+  }
   if (!want_unsafe_requests) {
     error("'pi' request is not allowed in safer mode");
     skip_line();
@@ -8175,6 +8188,8 @@ void pipe_output()
     }
     else {
       char *pc = read_string();
+      // This shouldn't happen thanks to `has_arg()` above.
+      assert(pc != 0 /* nullptr */);
       if (0 /* nullptr */ == pc)
        error("cannot apply pipe request to empty command");
       // Are we adding to an existing pipeline?
@@ -8200,12 +8215,20 @@ static int system_status;
 
 void system_request()
 {
+  if (!has_arg()) {
+    warning(WARN_MISSING, "system command execution request expects a"
+           " system command as argument");
+    skip_line();
+    return;
+  }
   if (!want_unsafe_requests) {
     error("'sy' request is not allowed in safer mode");
     skip_line();
   }
   else {
     char *command = read_string();
+    // This shouldn't happen thanks to `has_arg()` above.
+    assert(command != 0 /* nullptr */);
     if (0 /* nullptr */ == command)
       error("empty command");
     else {

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

Reply via email to