Subject: Re: lib/33841: getopt_long results in core dump
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-bugs
Date: 06/28/2006 13:10:02
The following reply was made to PR lib/33841; it has been noted by GNATS.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org,
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: lib/33841: getopt_long results in core dump
Date: Wed, 28 Jun 2006 09:08:45 -0400

 On Jun 27,  9:30pm, cheusov@tut.by (cheusov@tut.by) wrote:
 -- Subject: lib/33841: getopt_long results in core dump
 
 | >Number:         33841
 | >Category:       lib
 | >Synopsis:       getopt_long is buggy and results in core dump
 | >Confidential:   no
 | >Severity:       serious
 | >Priority:       high
 | >Responsible:    lib-bug-people
 | >State:          open
 | >Class:          sw-bug
 | >Submitter-Id:   net
 | >Arrival-Date:   Tue Jun 27 21:30:00 +0000 2006
 | >Originator:     cheusov@tut.by
 | >Release:        NetBSD 3.0_STABLE
 | >Organization:
 | Best regards, Aleksey Cheusov.
 | >Environment:
 | System: NetBSD chen.chizhovka.net 3.0_STABLE NetBSD 3.0_STABLE (GENERIC) #2: Sun Mar 12 12:49:58 GMT 2006 cheusov@chen:/usr/src/sys/arch/i386/compile/GENERIC i386
 | Architecture: i386
 | Machine: i386
 | >Description:
 | See How-To-Repeat section
 | >How-To-Repeat:
 | 0 #cat main.c
 | #include <getopt.h>
 | #include <stdio.h>
 | 
 | int main (int argc, char **argv)
 | {
 |         int c;
 | 
 |         struct option longopts [] = {
 |                 {"foo", no_argument, 0, 'f'},
 |         };
 | 
 |         c = getopt_long (argc, argv, "f", longopts, NULL);
 |         printf ("c=%d\n", c);
 | 
 |         return 0;
 | }
 | 0 #g++ -o main main.c
 | 0 #./main -f
 | c=102
 | 0 #./main --foo
 | c=102
 | 0 #./main -b
 | main: unknown option -- b
 | c=63
 | 0 #./main --bar
 | Segmentation fault (core dumped)
 | 139 #
 | 
 
 Your longopts array does not terminate in an empty element as it is
 supposed to.
 
 christos