Project

General

Profile

Actions

Bug #4716

open

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

Added by Jens Elkner over 9 years ago. Updated about 9 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
Gerrit CR:
External Bug:

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++;

Actions #1

Updated by Sachidananda Urs about 9 years ago

Do you a program to reproduce this issue?

Actions #2

Updated by Jens Elkner about 9 years ago

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

Actions

Also available in: Atom PDF