This is the mail archive of the libc-alpha@sourceware.cygnus.com 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]

["Andrew Wiseman" <a.wiseman@bandc.dircon.co.uk>] libc/1677: gcc-lib : getopt(0,argv,"a:b:c") causes segmentation fault



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



Topics:
   libc/1677: gcc-lib : getopt(0,argv,"a:b:c") causes segmentation fault


----------------------------------------------------------------------

Date: Wed, 29 Mar 2000 11:51:06 +0100
From: "Andrew Wiseman" <a.wiseman@bandc.dircon.co.uk>
To: <bugs@gnu.org>
Subject: libc/1677: gcc-lib : getopt(0,argv,"a:b:c") causes segmentation fault
Message-Id: <NBBBLEHDEKMCNNANFHAKGEHDDHAA.a.wiseman@bandc.dircon.co.uk>


>Number:         1677
>Category:       libc
>Synopsis:       passing 0 as first arg to getopt() causes segmentation fault
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    libc-gnats
>State:          open
>Class:          sw-bug
>Submitter-Id:   unknown
>Arrival-Date:   Wed Mar 29 06:00:03 EST 2000
>Last-Modified:
>Originator:     Andrew Wiseman
>Organization:
 Bensasson & Chalmers Limited, Cambridge, UK.
>Release:        libc-2.1.2
>Environment:
	PC with Cyrix 6x86x processor running at 133MHz
	Linux Mandrake 7.0
Host type: i586-mandrake-linux-gnu
System: Linux test 2.2.14-15mdk #1 Tue Jan 4 22:24:20 CET 2000 i586 unknown
Architecture: i586

Addons: crypt glibc-compat linuxthreads
Build CFLAGS: -mpentium -D__USE_STRING_INLINES -fstrict-aliasing -g -O3
Build CC: gcc
Compiler version: 2.95.2 19991024 (release)
Kernel headers: 2.2.14-15mdk
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Stdio: libio

>Description:
	passing 0 as first arg to getopt() causes segmentation fault
	.
	Found this in some old code I was trying to compile. The author decided
	he wasn't interested in picking up the programs command line options,
	and so when he called the general purpose initialising code, he passed
	in 0 rather than int argc.
>How-To-Repeat:
	#include <unistd.h>
	main(argc,argv)
	int argc;
	char *argv[];
	{
	    int ii = getopt(0,argv,"hm:n:c:dq");
	}
>Fix:
	None.


>Audit-Trail:
>Unformatted:


------------------------------

End of forwardIDGlog Digest
***************************



-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de

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