public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/11040] New: getopt mistakenly allows '-;' as short option
@ 2009-12-01 16:51 ebb9 at byu dot net
2009-12-01 16:54 ` [Bug libc/11040] " ebb9 at byu dot net
2010-04-08 0:31 ` drepper at redhat dot com
0 siblings, 2 replies; 3+ messages in thread
From: ebb9 at byu dot net @ 2009-12-01 16:51 UTC (permalink / raw)
To: glibc-bugs
getopt_long is documented as accepting an optstring of "W;" as an extension that
parses '-W longopt=value' the same as '--longopt=value'. However, using this
extension also makes apps mistakenly accept '-;' as a valid short option.
In practice, encountering '-;' as a short option will be rare (since it requires
shell quoting). Furthermore, if ';' appears in optstring outside of the
documented "W;" extension, there is no reason to forbid it from being a valid
short option as an extension permitted by POSIX. However, if the only ';' in
optstring immediately follows 'W', it makes more sense to reject ';', the same
way that ':' is rejected. And coding-wise, it is easier to forbid all use of
';', rather than making the code more complicated to determine whether ';' in
optstring immediately follows 'W'.
$ cat foo.c
#include <unistd.h>
#include <stdio.h>
#include <getopt.h>
static const struct option opts[] =
{
{ "alpha", no_argument, NULL, 'a' },
{ "beta", required_argument, NULL, 'b' },
{ NULL, 0, NULL, 0 }
};
int
main (int argc, char **argv)
{
int c = getopt_long (argc, argv, "ab:W;", opts, NULL);
if (c == -1)
puts ("got -1");
else
printf ("got %c\n", c);
c = getopt_long (argc, argv, "ab:W;", opts, NULL);
if (c == -1)
puts ("got -1");
else
printf ("got %c\n", c);
return 0;
}
$ ./foo '-a;'
got a
got ;
$ ./foo2 '-a:'
got a
./foo2: invalid option -- :
got ?
Workaround: code using the "W;" extension must be prepared to deal with a return
value of ';' and manually handle it as an invalid option.
Expected results: '-a;' should have errored out like '-a:'.
--
Summary: getopt mistakenly allows '-;' as short option
Product: glibc
Version: 2.11
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: ebb9 at byu dot net
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=11040
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libc/11040] getopt mistakenly allows '-;' as short option
2009-12-01 16:51 [Bug libc/11040] New: getopt mistakenly allows '-;' as short option ebb9 at byu dot net
@ 2009-12-01 16:54 ` ebb9 at byu dot net
2010-04-08 0:31 ` drepper at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: ebb9 at byu dot net @ 2009-12-01 16:54 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From ebb9 at byu dot net 2009-12-01 16:54 -------
Created an attachment (id=4436)
--> (http://sourceware.org/bugzilla/attachment.cgi?id=4436&action=view)
patch
2009-12-01 Eric Blake <ebb9@byu.net>
* posix/getopt.c (_getopt_internal_r): Reject '-;' as short
option, since it conflicts with "W;" optstring extension.
--
http://sourceware.org/bugzilla/show_bug.cgi?id=11040
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libc/11040] getopt mistakenly allows '-;' as short option
2009-12-01 16:51 [Bug libc/11040] New: getopt mistakenly allows '-;' as short option ebb9 at byu dot net
2009-12-01 16:54 ` [Bug libc/11040] " ebb9 at byu dot net
@ 2010-04-08 0:31 ` drepper at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: drepper at redhat dot com @ 2010-04-08 0:31 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From drepper at redhat dot com 2010-04-08 00:31 -------
Fixed in git.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://sourceware.org/bugzilla/show_bug.cgi?id=11040
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-04-08 0:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-01 16:51 [Bug libc/11040] New: getopt mistakenly allows '-;' as short option ebb9 at byu dot net
2009-12-01 16:54 ` [Bug libc/11040] " ebb9 at byu dot net
2010-04-08 0:31 ` drepper 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).