aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-29 14:32:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-29 14:32:17 +0200
commit6016181b68a9e8a9fb99893242851128b6bd5656 (patch)
tree5aeff977b9cf7b68a32dc7e9efe183a5f7173ba6
parent55af51c66d0dae27d188974820c4a7d53dd0be55 (diff)
downloadbusybox-w32-6016181b68a9e8a9fb99893242851128b6bd5656.tar.gz
busybox-w32-6016181b68a9e8a9fb99893242851128b6bd5656.tar.bz2
busybox-w32-6016181b68a9e8a9fb99893242851128b6bd5656.zip
hush: GETOPT_RESET() _after_ getopts too.
NOEXEC'ed applets which use getopt() need this. function old new delta builtin_getopts 403 413 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/getopt32.c2
-rw-r--r--shell/hush.c3
-rw-r--r--shell/shell_common.c4
4 files changed, 6 insertions, 5 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 95a7470a8..06f887732 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1212,7 +1212,7 @@ uint32_t getopt32long(char **argv, const char *optstring, const char *longopts,
1212 * By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0 1212 * By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0
1213 * (to interpret it as if optreset was set). 1213 * (to interpret it as if optreset was set).
1214 */ 1214 */
1215#ifdef __GLIBC__ 1215#if 1 /*def __GLIBC__*/
1216#define GETOPT_RESET() (optind = 0) 1216#define GETOPT_RESET() (optind = 0)
1217#else /* BSD style */ 1217#else /* BSD style */
1218#define GETOPT_RESET() (optind = 1) 1218#define GETOPT_RESET() (optind = 1)
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index f778c6e89..378510063 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -517,7 +517,7 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
517 } 517 }
518 518
519 /* In case getopt32 was already called: 519 /* In case getopt32 was already called:
520 * reset the libc getopt() function, which keeps internal state. 520 * reset libc getopt() internal state.
521 * run_nofork_applet() does this, but we might end up here 521 * run_nofork_applet() does this, but we might end up here
522 * also via gunzip_main() -> gzip_main(). Play safe. 522 * also via gunzip_main() -> gzip_main(). Play safe.
523 */ 523 */
diff --git a/shell/hush.c b/shell/hush.c
index 8e0022531..d27550ba0 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9956,7 +9956,7 @@ Test that VAR is a valid variable name?
9956 * until we get Nth result (or failure). 9956 * until we get Nth result (or failure).
9957 * (N == G.getopt_count is reset to 0 whenever OPTIND is [un]set). 9957 * (N == G.getopt_count is reset to 0 whenever OPTIND is [un]set).
9958 */ 9958 */
9959 optind = 0; /* reset getopt() state */ 9959 GETOPT_RESET();
9960 count = 0; 9960 count = 0;
9961 n = string_array_len(argv); 9961 n = string_array_len(argv);
9962 do { 9962 do {
@@ -9971,6 +9971,7 @@ Test that VAR is a valid variable name?
9971 /* Set OPTIND. Prevent resetting of the magic counter! */ 9971 /* Set OPTIND. Prevent resetting of the magic counter! */
9972 set_local_var_from_halves("OPTIND", utoa(optind)); 9972 set_local_var_from_halves("OPTIND", utoa(optind));
9973 G.getopt_count = count; /* "next time, give me N+1'th result" */ 9973 G.getopt_count = count; /* "next time, give me N+1'th result" */
9974 GETOPT_RESET(); /* just in case */
9974 9975
9975 /* Set OPTARG */ 9976 /* Set OPTARG */
9976 /* Always set or unset, never left as-is, even on exit/error: 9977 /* Always set or unset, never left as-is, even on exit/error:
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 7a0799ed5..c978693f9 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -425,8 +425,8 @@ shell_builtin_ulimit(char **argv)
425 * ulimit 123 -c2 -l 456 425 * ulimit 123 -c2 -l 456
426 */ 426 */
427 427
428 /* In case getopt was already called: 428 /* In case getopt() was already called:
429 * reset the libc getopt() function, which keeps internal state. 429 * reset libc getopt() internal state.
430 */ 430 */
431 GETOPT_RESET(); 431 GETOPT_RESET();
432 432