aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-11-24 00:22:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-11-24 00:22:42 +0000
commitc3c6659f12e4133054ae4a6708fc4ac299c0d098 (patch)
tree588de32513e22a75e8f45d450b9d25a965a2c444
parentd2023283ac87737cf0fbd77f4cbb1bb7b390009d (diff)
downloadbusybox-w32-c3c6659f12e4133054ae4a6708fc4ac299c0d098.tar.gz
busybox-w32-c3c6659f12e4133054ae4a6708fc4ac299c0d098.tar.bz2
busybox-w32-c3c6659f12e4133054ae4a6708fc4ac299c0d098.zip
hush: fix segfault in "echo $@" when we have no arguments
-rw-r--r--shell/hush.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/shell/hush.c b/shell/hush.c
index b3c77aa14..a9c1fe7dd 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2468,7 +2468,7 @@ static void count_var_expansion_space(int *countp, int *lenp, char *arg)
2468 break; 2468 break;
2469 case '*': 2469 case '*':
2470 case '@': 2470 case '@':
2471 for (i = 1; i < global_argc; i++) { 2471 for (i = 1; global_argv[i]; i++) {
2472 len += strlen(global_argv[i]) + 1; 2472 len += strlen(global_argv[i]) + 1;
2473 count++; 2473 count++;
2474 if (!(first_ch & 0x80)) 2474 if (!(first_ch & 0x80))
@@ -2581,11 +2581,13 @@ static int expand_vars_to_list(char **list, int n, char **posp, char *arg, char
2581 case '*': 2581 case '*':
2582 case '@': 2582 case '@':
2583 i = 1; 2583 i = 1;
2584 if (!global_argv[i])
2585 break;
2584 if (!(first_ch & 0x80)) { /* unquoted $* or $@ */ 2586 if (!(first_ch & 0x80)) { /* unquoted $* or $@ */
2585 while (i < global_argc) { 2587 while (global_argv[i]) {
2586 n = expand_on_ifs(list, n, &pos, global_argv[i]); 2588 n = expand_on_ifs(list, n, &pos, global_argv[i]);
2587 debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, global_argc-1); 2589 debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, global_argc-1);
2588 if (global_argv[i++][0] && i < global_argc) { 2590 if (global_argv[i++][0] && global_argv[i]) {
2589 /* this argv[] is not empty and not last: 2591 /* this argv[] is not empty and not last:
2590 * put terminating NUL, start new word */ 2592 * put terminating NUL, start new word */
2591 *pos++ = '\0'; 2593 *pos++ = '\0';
@@ -2611,7 +2613,7 @@ static int expand_vars_to_list(char **list, int n, char **posp, char *arg, char
2611 list[n++] = pos; 2613 list[n++] = pos;
2612 } 2614 }
2613 } else { /* quoted $*: add as one word */ 2615 } else { /* quoted $*: add as one word */
2614 if (global_argv[i]) while (1) { 2616 while (1) {
2615 strcpy(pos, global_argv[i]); 2617 strcpy(pos, global_argv[i]);
2616 pos += strlen(global_argv[i]); 2618 pos += strlen(global_argv[i]);
2617 if (!global_argv[++i]) 2619 if (!global_argv[++i])