This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/12922] New: getopt dumps core


http://sourceware.org/bugzilla/show_bug.cgi?id=12922

           Summary: getopt dumps core
           Product: glibc
           Version: 2.14
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: eblake@redhat.com


Detected by Clang:
http://www.gnupdf.org/prmgt/clang/report-kFVhsy.html#EndPath

$ cat foo.c
#include <unistd.h>
int
main (int argc, char **argv)
{
  getopt (argc, argv, "W;");
  return 0;
}
$ ./foo -Wb
Segmentation fault (core dumped)

backtrace:
Program received signal SIGSEGV, Segmentation fault.
0x0000003d15ec7ba8 in _getopt_internal_r (argc=<value optimized out>, 
    argv=0x7fffffffe1c8, optstring=0x400608 "W;", longopts=0x0, longind=0x0, 
    long_only=0, d=0x3d16198460, posixly_correct=1) at getopt.c:899
899        for (p = longopts, option_index = 0; p->name; p++, option_index++)
(gdb) bt
#0  0x0000003d15ec7ba8 in _getopt_internal_r (argc=<value optimized out>, 
    argv=0x7fffffffe1c8, optstring=0x400608 "W;", longopts=0x0, longind=0x0, 
    long_only=0, d=0x3d16198460, posixly_correct=1) at getopt.c:899
#1  0x0000003d15ec844b in _getopt_internal (argc=<value optimized out>, 
    argv=<value optimized out>, optstring=<value optimized out>, 
    longopts=<value optimized out>, longind=<value optimized out>, 
    long_only=<value optimized out>, posixly_correct=1) at getopt.c:1131
#2  0x0000003d15ec84b8 in __posix_getopt (argc=<value optimized out>, 
    argv=<value optimized out>, optstring=<value optimized out>)
    at getopt.c:1155
#3  0x0000000000400509 in main ()

culprit: getopt is blindly assuming a non-NULL long options if the short
options string contains the sequence "W;".

Technically, the above program is in violation of POSIX (";" does not have
specified behavior as an option character in getopt), but since the crash can
also occur with getopt_long, it might make sense to diagnose NULL longopts
paired with "W;" as a programming error rather than blindly crashing.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]