gbranden pushed a commit to branch master
in repository groff.

commit 6dee590de89d40ba50e1e337df54956b691203f1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Sep 12 00:16:25 2024 -0500

    src/roff/troff/input.cpp: Add "missing" warnings.
    
    * src/roff/troff/input.cpp (source_request)
      (source_quietly_request, pipe_source_request, open_request)
      (opena_request, close_request, macro_source_request)
      (macro_source_quietly_request, ps_bbox_request): Check for arguments:
      if none are present, throw warning in category "missing" and skip the
      remainder of the input line.
---
 ChangeLog                |  9 ++++++++
 src/roff/troff/input.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 33f802099..4123ab601 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,15 @@
        might not notice right away.  Fixes problem introduced by me in
        commit 3bb13e4752, 4 September.
 
+2024-09-11  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (source_request)
+       (source_quietly_request, pipe_source_request, open_request)
+       (opena_request, close_request, macro_source_request)
+       (macro_source_quietly_request, ps_bbox_request): Check for
+       arguments: if none are present, throw warning in category
+       "missing" and skip the remainder of the input line.
+
 2024-09-11  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp: Trivially refactor.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 7890c9600..06caafedb 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -6451,6 +6451,11 @@ void do_source(bool quietly)
 
 void source_request() // .so
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "file sourcing request expects an argument");
+    skip_line();
+    return;
+  }
   do_source(false /* quietly */ );
 }
 
@@ -6458,11 +6463,22 @@ void source_request() // .so
 // nonexistence
 void source_quietly_request() // .soquiet
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "quiet file sourcing request expects an"
+           " argument");
+    skip_line();
+    return;
+  }
   do_source(true /* quietly */ );
 }
 
 void pipe_source_request() // .pso
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "pipe sourcing request expects arguments");
+    skip_line();
+    return;
+  }
   if (!want_unsafe_requests) {
     error("piped command source request is not allowed in safer mode");
     skip_line();
@@ -6950,12 +6966,14 @@ inline int psbb_locator::skip_to_trailer(void)
   return 0;
 }
 
-// ps_bbox_request()
-//
-// Handle the .psbb request.
-//
-void ps_bbox_request()
+void ps_bbox_request() // .psbb
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "PostScript file bounding box extraction"
+           " request expects an argument");
+    skip_line();
+    return;
+  }
   // Parse input line, to extract file name.
   //
   symbol nm = get_long_name(true /* required */);
@@ -7223,6 +7241,11 @@ static void open_file(bool appending)
 
 static void open_request() // .open
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "file writing request expects arguments");
+    skip_line();
+    return;
+  }
   if (!want_unsafe_requests) {
     error("file writing request is not allowed in safer mode");
     skip_line();
@@ -7233,6 +7256,11 @@ static void open_request() // .open
 
 static void opena_request() // .opena
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "file appending request expects arguments");
+    skip_line();
+    return;
+  }
   if (!want_unsafe_requests) {
     error("file appending request is not allowed in safer mode");
     skip_line();
@@ -7243,6 +7271,11 @@ static void opena_request() // .opena
 
 static void close_request() // .close
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "stream closing request expects an argument");
+    skip_line();
+    return;
+  }
   symbol stream = get_name(true /* required */);
   if (!stream.is_null()) {
     FILE *fp = (FILE *)stream_dictionary.remove(stream);
@@ -8483,6 +8516,12 @@ void do_macro_source(bool quietly)
 
 void macro_source_request() // .mso
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "macro file sourcing request expects an"
+           " argument");
+    skip_line();
+    return;
+  }
   do_macro_source(false /* quietly */ );
 }
 
@@ -8490,6 +8529,12 @@ void macro_source_request() // .mso
 // their nonexistence
 void macro_source_quietly_request() // .msoquiet
 {
+  if (!has_arg(true /* peek */)) {
+    warning(WARN_MISSING, "quiet macro file sourcing request expects an"
+           " argument");
+    skip_line();
+    return;
+  }
   do_macro_source(true /* quietly */ );
 }
 

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

Reply via email to