aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-18 17:49:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-18 17:49:58 +0000
commit324a3fdf87acf5d7e7bd852df921b19b97707ce8 (patch)
tree11efea2e0914ca9b68ef411f3509d33c470ec417
parent4a689e9b49a0a40c062c5e4b1d46a100ec7f6d85 (diff)
downloadbusybox-w32-324a3fdf87acf5d7e7bd852df921b19b97707ce8.tar.gz
busybox-w32-324a3fdf87acf5d7e7bd852df921b19b97707ce8.tar.bz2
busybox-w32-324a3fdf87acf5d7e7bd852df921b19b97707ce8.zip
fix globbing in unquoted $* and $@
-rw-r--r--shell/hush.c17
-rw-r--r--shell/hush_test/hush-vars/param_glob.right4
-rwxr-xr-xshell/hush_test/hush-vars/param_glob.tests10
3 files changed, 25 insertions, 6 deletions
diff --git a/shell/hush.c b/shell/hush.c
index b83265899..4d7d14b1a 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -342,6 +342,8 @@ typedef struct {
342 char *data; 342 char *data;
343 int length; 343 int length;
344 int maxlen; 344 int maxlen;
345 /* Misnomer! it's not "quoting", it's "protection against globbing"!
346 * (by prepending \ to *, ?, [ and to \ too) */
345 smallint o_quote; 347 smallint o_quote;
346 smallint o_glob; 348 smallint o_glob;
347 smallint nonnull; 349 smallint nonnull;
@@ -2398,8 +2400,10 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
2398 if (!global_argv[i]) 2400 if (!global_argv[i])
2399 break; 2401 break;
2400 if (!(first_ch & 0x80)) { /* unquoted $* or $@ */ 2402 if (!(first_ch & 0x80)) { /* unquoted $* or $@ */
2403 smallint sv = output->o_quote;
2404 /* unquoted var's contents should be globbed, so don't quote */
2405 output->o_quote = 0;
2401 while (global_argv[i]) { 2406 while (global_argv[i]) {
2402//see expand_on_ifs below - same??
2403 n = expand_on_ifs(output, n, global_argv[i]); 2407 n = expand_on_ifs(output, n, global_argv[i]);
2404 debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, global_argc-1); 2408 debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, global_argc-1);
2405 if (global_argv[i++][0] && global_argv[i]) { 2409 if (global_argv[i++][0] && global_argv[i]) {
@@ -2411,12 +2415,13 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
2411 debug_print_list("expand_vars_to_list[3]", output, n); 2415 debug_print_list("expand_vars_to_list[3]", output, n);
2412 } 2416 }
2413 } 2417 }
2418 output->o_quote = sv;
2414 } else 2419 } else
2415 /* If or_mask is nonzero, we handle assignment 'a=....$@.....' 2420 /* If or_mask is nonzero, we handle assignment 'a=....$@.....'
2416 * and in this case should treat it like '$*' - see 'else...' below */ 2421 * and in this case should treat it like '$*' - see 'else...' below */
2417 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */ 2422 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */
2418 while (1) { 2423 while (1) {
2419 o_addQstr(output, global_argv[i], strlen(global_argv[i])); ///really Q? 2424 o_addQstr(output, global_argv[i], strlen(global_argv[i]));
2420 if (++i >= global_argc) 2425 if (++i >= global_argc)
2421 break; 2426 break;
2422 o_addchr(output, '\0'); 2427 o_addchr(output, '\0');
@@ -2425,7 +2430,7 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
2425 } 2430 }
2426 } else { /* quoted $*: add as one word */ 2431 } else { /* quoted $*: add as one word */
2427 while (1) { 2432 while (1) {
2428 o_addQstr(output, global_argv[i], strlen(global_argv[i])); ///really Q? 2433 o_addQstr(output, global_argv[i], strlen(global_argv[i]));
2429 if (!global_argv[++i]) 2434 if (!global_argv[++i])
2430 break; 2435 break;
2431 if (ifs[0]) 2436 if (ifs[0])
@@ -2482,7 +2487,7 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
2482 } 2487 }
2483 } 2488 }
2484 if (val) { 2489 if (val) {
2485 o_addQstr(output, val, strlen(val)); ///maybe q? 2490 o_addQstr(output, val, strlen(val));
2486 } 2491 }
2487 2492
2488#if ENABLE_HUSH_TICK 2493#if ENABLE_HUSH_TICK
@@ -2517,8 +2522,8 @@ static char **expand_variables(char **argv, int or_mask)
2517 o_string output = NULL_O_STRING; 2522 o_string output = NULL_O_STRING;
2518 2523
2519 if (or_mask & 0x100) { 2524 if (or_mask & 0x100) {
2520 output.o_quote = 1; 2525 output.o_quote = 1; /* protect against globbing for "$var" */
2521/* why? */ 2526 /* (unquoted $var will temporarily switch it off) */
2522 output.o_glob = 1; 2527 output.o_glob = 1;
2523 } 2528 }
2524 2529
diff --git a/shell/hush_test/hush-vars/param_glob.right b/shell/hush_test/hush-vars/param_glob.right
new file mode 100644
index 000000000..bdee8fe0f
--- /dev/null
+++ b/shell/hush_test/hush-vars/param_glob.right
@@ -0,0 +1,4 @@
1param_glob.tests
2param_glob.tests
3param_glob.t*
4param_glob.t*
diff --git a/shell/hush_test/hush-vars/param_glob.tests b/shell/hush_test/hush-vars/param_glob.tests
new file mode 100755
index 000000000..801d58ee7
--- /dev/null
+++ b/shell/hush_test/hush-vars/param_glob.tests
@@ -0,0 +1,10 @@
1if test $# = 0; then
2 #BUG in builtin_exec! will glob param!
3 #exec "$THIS_SH" "$0" 'param_glob.t*'
4 "$THIS_SH" "$0" 'param_glob.t*'
5 exit
6fi
7echo $*
8echo $@
9echo "$*"
10echo "$@"