["Andrew Wiseman" <a.wiseman@bandc.dircon.co.uk>] libc/1677: gcc-lib : getopt(0,argv,"a:b:c") causes segmentation fault
Andreas Jaeger
aj@suse.de
Wed Mar 29 04:54:00 GMT 2000
We received the appended bug report from Andrew Wiseman. Since getopt
(0,...) is not forbidden, we should check for it.
Currently we expect implicitly that argc is > 0. Here's the backtrace
from gdb for the program:
Program received signal SIGSEGV, Segmentation fault.
0x400bed22 in _getopt_internal (argc=0, argv=0xbffff7e4,
optstring=0x8048480 "hm:n:c:dq", longopts=0x0, longind=0x0, long_only=0)
at getopt.c:580
580 if (optind != argc && !strcmp (argv[optind], "--"))
(gdb) p optind
$1 = 1
(gdb) bt
#0 0x400bed22 in _getopt_internal (argc=0, argv=0xbffff7e4,
optstring=0x8048480 "hm:n:c:dq", longopts=0x0, longind=0x0, long_only=0)
at getopt.c:580
#1 0x400bf90c in getopt () at getopt.c:969
#2 0x8048419 in main (argc=1, argv=0xbffff7e4) at pr1677.c:6
We could add a
if (argc < 1)
return -1;
at the beginning of _getopt_internal.
Anyone with a better idea?
Andreas
More information about the Libc-alpha
mailing list