Re:  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=716285

I reproduced this crash locally.  It is related to the behavior of
the custom getopt function when an option's argument is missing.
Please review the attached patch, which avoids the crash at least.

Ultimately, this program should probably no longer include its own getopt.
This may have been necessary long ago, but it is unlikely to be
necessary today.

-Brian Gaeke

diff -u -r ratfor-1.0-15/rat4.c ratfor-1.0-15+patch/rat4.c
--- ratfor-1.0-15/rat4.c        2015-09-20 00:34:34.388746538 -0700
+++ ratfor-1.0-15+patch/rat4.c  2015-09-20 00:37:32.668976695 -0700
@@ -183,7 +183,13 @@
                                /* not written yet */
                        break;
                case 'l':       /* user sets label */
-                       startlab = atoi(optarg);
+                       if (optarg != NULL)
+                               startlab = atoi(optarg);
+                       else {
+                               fprintf(stderr,
+                                       "-l requires an integer argument\n");
+                               exit(1);
+                       }
                        break;
                case 'o':
                        if ((freopen(optarg, "w", stdout)) == NULL)

Reply via email to