Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
getopt mishandles optstring of "+:"
  • Loading branch information
Eric Blake authored and Ulrich Drepper committed Apr 8, 2010
1 parent cf0b681 commit 66b93be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,5 +1,9 @@
2009-12-01 Eric Blake <ebb9@byu.net>

[BZ #11039]
* posix/getopt.c (_getopt_internal_r): Skip optional - or + before
checking lead byte of optstring for :.

[BZ #11040]
* posix/getopt.c (_getopt_internal_r): Reject '-;' as short
option, since it conflicts with "W;" optstring extension.
Expand Down
6 changes: 4 additions & 2 deletions posix/getopt.c
Expand Up @@ -395,8 +395,6 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
int long_only, struct _getopt_data *d, int posixly_correct)
{
int print_errors = d->opterr;
if (optstring[0] == ':')
print_errors = 0;

if (argc < 1)
return -1;
Expand All @@ -411,6 +409,10 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
posixly_correct);
d->__initialized = 1;
}
else if (optstring[0] == '-' || optstring[0] == '+')
optstring++;
if (optstring[0] == ':')
print_errors = 0;

/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag
Expand Down

0 comments on commit 66b93be

Please sign in to comment.