Project

General

Profile

Bug #4716

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

Added by Jens Elkner about 5 years ago. Updated over 4 years ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
-
Start date:
2014-03-30
Due date:
% Done:

0%

Estimated time:
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 over 4 years ago

Do you a program to reproduce this issue?

#2

Updated by Jens Elkner over 4 years ago

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

Also available in: Atom PDF