diff options
author | Denis Vlasenko | 2008-11-12 22:06:46 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-11-12 22:06:46 +0000 |
commit | fd5a3d28127f051887b6feb3462928aee045c9ef (patch) | |
tree | f43a8394cb6cbd93f82a8cccecab7206a7c3f0c7 /libbb | |
parent | 7753ea49bd435d2f5d4a47d50fcfd4efcd52cad8 (diff) | |
download | busybox-fd5a3d28127f051887b6feb3462928aee045c9ef.zip busybox-fd5a3d28127f051887b6feb3462928aee045c9ef.tar.gz |
gzip: fix gzip -dc case caused by using stale getopt state
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/getopt32.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 49fb533..5190fa6 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -155,9 +155,9 @@ Special characters: Allows any arguments to be given without a dash (./program w x) as well as with a dash (./program -x). - NB: getopt32() will leak a small amount of memory if you use - this option! Do not use it if there is a possibility of recursive - getopt32() calls. + NB: getopt32() will leak a small amount of memory if you use + this option! Do not use it if there is a possibility of recursive + getopt32() calls. "--" A double dash at the beginning of opt_complementary means the argv[1] string should always be treated as options, even if it isn't @@ -165,9 +165,9 @@ Special characters: such as "ar" and "tar": tar xvf foo.tar - NB: getopt32() will leak a small amount of memory if you use - this option! Do not use it if there is a possibility of recursive - getopt32() calls. + NB: getopt32() will leak a small amount of memory if you use + this option! Do not use it if there is a possibility of recursive + getopt32() calls. "-N" A dash as the first char in a opt_complementary group followed by a single digit (0-9) means that at least N non-option @@ -515,6 +515,19 @@ getopt32(char **argv, const char *applet_opts, ...) } } + /* In case getopt32 was already called: + * reset the libc getopt() function, which keeps internal state. + * run_nofork_applet_prime() does this, but we might end up here + * also via gunzip_main() -> gzip_main(). Play safe. + */ +#ifdef __GLIBC__ + optind = 0; +#else /* BSD style */ + optind = 1; + /* optreset = 1; */ +#endif + /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */ + pargv = NULL; /* Note: just "getopt() <= 0" will not work well for |