aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-11-12 22:06:46 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-11-12 22:06:46 +0000
commitfd5a3d28127f051887b6feb3462928aee045c9ef (patch)
treef43a8394cb6cbd93f82a8cccecab7206a7c3f0c7
parent7753ea49bd435d2f5d4a47d50fcfd4efcd52cad8 (diff)
downloadbusybox-w32-fd5a3d28127f051887b6feb3462928aee045c9ef.tar.gz
busybox-w32-fd5a3d28127f051887b6feb3462928aee045c9ef.tar.bz2
busybox-w32-fd5a3d28127f051887b6feb3462928aee045c9ef.zip
gzip: fix gzip -dc case caused by using stale getopt state
-rw-r--r--libbb/getopt32.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 49fb5335d..5190fa61a 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -155,9 +155,9 @@ Special characters:
155 Allows any arguments to be given without a dash (./program w x) 155 Allows any arguments to be given without a dash (./program w x)
156 as well as with a dash (./program -x). 156 as well as with a dash (./program -x).
157 157
158 NB: getopt32() will leak a small amount of memory if you use 158 NB: getopt32() will leak a small amount of memory if you use
159 this option! Do not use it if there is a possibility of recursive 159 this option! Do not use it if there is a possibility of recursive
160 getopt32() calls. 160 getopt32() calls.
161 161
162 "--" A double dash at the beginning of opt_complementary means the 162 "--" A double dash at the beginning of opt_complementary means the
163 argv[1] string should always be treated as options, even if it isn't 163 argv[1] string should always be treated as options, even if it isn't
@@ -165,9 +165,9 @@ Special characters:
165 such as "ar" and "tar": 165 such as "ar" and "tar":
166 tar xvf foo.tar 166 tar xvf foo.tar
167 167
168 NB: getopt32() will leak a small amount of memory if you use 168 NB: getopt32() will leak a small amount of memory if you use
169 this option! Do not use it if there is a possibility of recursive 169 this option! Do not use it if there is a possibility of recursive
170 getopt32() calls. 170 getopt32() calls.
171 171
172 "-N" A dash as the first char in a opt_complementary group followed 172 "-N" A dash as the first char in a opt_complementary group followed
173 by a single digit (0-9) means that at least N non-option 173 by a single digit (0-9) means that at least N non-option
@@ -515,6 +515,19 @@ getopt32(char **argv, const char *applet_opts, ...)
515 } 515 }
516 } 516 }
517 517
518 /* In case getopt32 was already called:
519 * reset the libc getopt() function, which keeps internal state.
520 * run_nofork_applet_prime() does this, but we might end up here
521 * also via gunzip_main() -> gzip_main(). Play safe.
522 */
523#ifdef __GLIBC__
524 optind = 0;
525#else /* BSD style */
526 optind = 1;
527 /* optreset = 1; */
528#endif
529 /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */
530
518 pargv = NULL; 531 pargv = NULL;
519 532
520 /* Note: just "getopt() <= 0" will not work well for 533 /* Note: just "getopt() <= 0" will not work well for