gbranden pushed a commit to branch master
in repository groff.

commit 83270d27305f55ef53aafa617f495402c293bef0
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 15 13:19:59 2026 -0500

    [gxditview]: Fix Savannah #68152.
    
    * src/devices/xditview/xditview.c (main): Avoid invalid memory access by
      checking that `argc` is greater than 1 before trying to access
      `argv[1]`.
    
    Fixes <https://savannah.gnu.org/bugs/?68152>.
    
    Also cosmetically update function calls to add space between the
    function name and the subsequent opening parenthesis.  I dislike this
    style, and it's not otherwise used in groff, but this MIT X Consortium
    code uses it.
---
 ChangeLog                       |  8 ++++++++
 src/devices/xditview/xditview.c | 24 +++++++++++++-----------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4248915c4..91e7c019a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-03-15  G. Branden Robinson <[email protected]>
+
+       * src/devices/xditview/xditview.c (main): Avoid invalid memory
+       access by checking that `argc` is greater than 1 before trying
+       to access `argv[1]`.
+
+       Fixes <https://savannah.gnu.org/bugs/?68152>.
+
 2026-03-15  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/reg.cpp (rename_register_request): Fix typo in
diff --git a/src/devices/xditview/xditview.c b/src/devices/xditview/xditview.c
index 849da742a..0890082ec 100644
--- a/src/devices/xditview/xditview.c
+++ b/src/devices/xditview/xditview.c
@@ -234,18 +234,20 @@ int main(int argc, char **argv)
      * XXX: This is not as flexible as GNU getopt, but good enough to
      * work when called by groff.
      */
-    if ((strcmp(argv[1], "-help") == 0)
-       || (strcmp(argv[1], "--help") == 0))
-           Syntax(argv[0], false /* did not have error */);
-    else if ((strcmp(argv[1], "-v") == 0)
-       || (strcmp(argv[1], "-version") == 0)
-       || (strcmp(argv[1], "--version") == 0)) {
-           (void) printf("GNU gxditview (groff) version %s\n",
-                         Version_string);
-           exit(EXIT_SUCCESS);
-    if (argc > 2)
-       Syntax(argv[0], true /* had error */);
+    if (argc > 1) {
+       if ((strcmp (argv[1], "-help") == 0)
+            || (strcmp (argv[1], "--help") == 0))
+               Syntax (argv[0], false /* did not have error */);
+       else if ((strcmp (argv[1], "-v") == 0)
+                || (strcmp (argv[1], "-version") == 0)
+                || (strcmp (argv[1], "--version") == 0)) {
+           (void) printf ("GNU gxditview (groff) version %s\n",
+                          Version_string);
+           exit (EXIT_SUCCESS);
+       }
     }
+    if (argc > 2)
+       Syntax (argv[0], true /* had error */);
 
     XtGetApplicationResources(toplevel, (XtPointer)&app_resources,
                              resources, XtNumber(resources),

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

Reply via email to