]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
getopt mishandles optstring of "+:"
authorEric Blake <ebb9@byu.net>
Thu, 8 Apr 2010 00:56:20 +0000 (17:56 -0700)
committerPetr Baudis <pasky@ucw.cz>
Wed, 12 May 2010 01:21:15 +0000 (03:21 +0200)
(cherry picked from commit 66b93be793af309fb78d54199aed2306650079d0)

ChangeLog
posix/getopt.c

index 1497e859b57b601f6d4e459cb8a17fc086ae6b0a..e2a23b7b500fe34841a4f6e94bfcc87c70b38b79 100644 (file)
--- a/ChangeLog
+++ b/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.
index b778047cd91256e0723967cff9183eb8247d805f..2746364fc73a332c157007a9e2b64078b6723aa6 100644 (file)
@@ -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;
@@ -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