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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
@ 2011-06-22 17:13 ` eblake at redhat dot com
  2011-07-07  1:30 ` drepper.fsp at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: eblake at redhat dot com @ 2011-06-22 17:13 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #1 from Eric Blake <eblake at redhat dot com> 2011-06-22 17:13:20 UTC ---
Potential patch:

diff --git i/posix/getopt.c w/posix/getopt.c
index db89abf..da6ce66 100644
--- i/posix/getopt.c
+++ w/posix/getopt.c
@@ -869,7 +869,7 @@ _getopt_internal_r (int argc, char *const *argv, const char
*optstring,
     return '?';
       }
     /* Convenience. Treat POSIX -W foo same as long option --foo */
-    if (temp[0] == 'W' && temp[1] == ';')
+    if (temp[0] == 'W' && temp[1] == ';' && longopts)
       {
     char *nameend;
     const struct option *p;

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

* [Bug libc/12922] getopt dumps core
  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
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-07-07  1:30 UTC (permalink / raw)
  To: glibc-bugs

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

Ulrich Drepper <drepper.fsp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #2 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-07-07 01:29:30 UTC ---
I checked in a patch.

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

* [Bug libc/12922] getopt dumps core
  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
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: eblake at redhat dot com @ 2011-07-07 14:49 UTC (permalink / raw)
  To: glibc-bugs

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

Eric Blake <eblake at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |

--- Comment #3 from Eric Blake <eblake at redhat dot com> 2011-07-07 14:49:29 UTC ---
(In reply to comment #2)
> I checked in a patch.

Except that your patch fails to compile with C89 compilers.  Can you also check
in this?

diff --git i/posix/getopt.c w/posix/getopt.c
index 3fa5a4d..e0e5503 100644
--- i/posix/getopt.c
+++ w/posix/getopt.c
@@ -871,9 +871,6 @@ _getopt_internal_r (int argc, char *const *argv, const char
*optstring,
     /* Convenience. Treat POSIX -W foo same as long option --foo */
     if (temp[0] == 'W' && temp[1] == ';')
       {
-    if (longopts == NULL)
-      goto no_longs;
-
     char *nameend;
     const struct option *p;
     const struct option *pfound = NULL;
@@ -882,6 +879,9 @@ _getopt_internal_r (int argc, char *const *argv, const char
*optstring,
     int indfound = 0;
     int option_index;

+    if (longopts == NULL)
+      goto no_longs;
+
     /* This is an option that requires an argument.  */
     if (*d->__nextchar != '\0')
       {

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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
                   ` (2 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-07-08 15:58 UTC (permalink / raw)
  To: glibc-bugs

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

Ulrich Drepper <drepper.fsp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #4 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-07-08 15:57:20 UTC ---
(In reply to comment #3)
> Except that your patch fails to compile with C89 compilers.

Who cares?  Stop bothering people with completely irrelevant stuff.

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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
                   ` (3 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: eblake at redhat dot com @ 2011-07-08 16:01 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #5 from Eric Blake <eblake at redhat dot com> 2011-07-08 16:00:53 UTC ---
(In reply to comment #4)
> (In reply to comment #3)
> > Except that your patch fails to compile with C89 compilers.
> 
> Who cares?

Right now, gnulib and glibc getopt.c are intentionally kept in sync.  This is
because _lots_ of projects use getopt.c verbatim in their projects when
compiling on non-glibc platforms.  And this includes with C89 compilers.

If you truly don't care about projects that want to port getopt.c outside of
glibc, then there is a LOT of cruft that can be removed (look at all the #ifdef
_LIBC stuff at the top of the file).  By keeping that portability headache, it
implies that you want to keep this file portable, and that (unfortunately)
still implies using C89 throughout the file.

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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
                   ` (4 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-07-08 17:11 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #6 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-07-08 17:11:05 UTC ---
C89 compilers are irrelevant.  It's 12 years since C99.  Get over it.

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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: schwab@linux-m68k.org @ 2012-04-02 15:14 UTC (permalink / raw)
  To: glibc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xu_zhong_xing at 163 dot
                   |                            |com

--- Comment #7 from Andreas Schwab <schwab@linux-m68k.org> 2012-04-02 15:13:24 UTC ---
*** Bug 13936 has been marked as a duplicate of this bug. ***

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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: jackie.rosen at hushmail dot com @ 2014-02-16 18:27 UTC (permalink / raw)
  To: glibc-bugs

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

Jackie Rosen <jackie.rosen at hushmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jackie.rosen at hushmail dot com

--- Comment #8 from Jackie Rosen <jackie.rosen at hushmail dot com> ---
*** Bug 260998 has been marked as a duplicate of this bug. ***
Seen from the domain http://volichat.com
Page where seen: http://volichat.com/adult-chat-rooms
Marked for reference. Resolved as fixed @bugzilla.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: schwab at sourceware dot org @ 2014-05-28 19:44 UTC (permalink / raw)
  To: glibc-bugs

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

Andreas Schwab <schwab at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|jackie.rosen at hushmail dot com   |

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug libc/12922] getopt dumps core
  2011-06-22 17:09 [Bug libc/12922] New: getopt dumps core eblake at redhat dot com
                   ` (8 preceding siblings ...)
  2014-05-28 19:44 ` schwab at sourceware dot org
@ 2014-06-25 11:24 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: fweimer at redhat dot com @ 2014-06-25 11:24 UTC (permalink / raw)
  To: glibc-bugs

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

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
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).