public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12922] New: getopt dumps core
@ 2011-06-22 17:09 eblake at redhat dot com
  2011-06-22 17:13 ` [Bug libc/12922] " eblake at redhat dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: eblake at redhat dot com @ 2011-06-22 17:09 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-06-25 11:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
2011-06-22 17:13 ` [Bug libc/12922] " eblake at redhat dot com
2011-07-07  1:30 ` drepper.fsp at gmail dot com
2011-07-07 14:49 ` eblake at redhat dot com
2011-07-08 15:58 ` drepper.fsp at gmail dot com
2011-07-08 16:01 ` eblake at redhat dot com
2011-07-08 17:11 ` drepper.fsp at gmail dot com
2012-04-02 15:14 ` schwab@linux-m68k.org
2014-02-16 18:27 ` jackie.rosen at hushmail dot com
2014-05-28 19:44 ` schwab at sourceware dot org
2014-06-25 11:24 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).