Bug #4716

getopt: check for NULL before accessing argv[n][m]

Added by Jens Elkner over 4 years ago. Updated almost 4 years ago.

Status:NewStart date:2014-03-30
Priority:LowDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Difficulty:Bite-size Tags:needs-triage

Description

getopt may SEGVs if argv[n] is NULL

--- getopt.c.orig    Sat Jun  1 03:27:56 2013
+++ getopt.c    Sun Mar 30 05:15:10 2014
@@ -196,8 +196,8 @@
      * getopt() returns -1 after incrementing optind.
      */
     if (_sp == 1) {
-        if (optind >= argc || argv[optind][0] != '-' ||
-            argv[optind] == NULL || argv[optind][1] == '\\0')
+        if (optind >= argc || argv[optind] == NULL ||
+            argv[optind][0] != '-' || argv[optind][1] == '\\0')
             return (EOF);
         else if (strcmp(argv[optind], "--") == NULL) {
             optind++;

History

#1 Updated by Sachidananda Urs almost 4 years ago

Do you a program to reproduce this issue?

#2 Updated by Jens Elkner almost 4 years ago

Obviously, otherwise I would not have digged into this thing. Anyway, does this matter?

Also available in: Atom