aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-11-23 21:08:38 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-11-23 21:08:38 +0000
commitcccdc4e01abb354c50aa483a21d5ff56a18c0b4a (patch)
tree4290b391d3ea634a0393082c2233935bf5357afc /shell/hush.c
parent835068637e81771a1b45b9faf04a31830f0e5d8a (diff)
downloadbusybox-w32-cccdc4e01abb354c50aa483a21d5ff56a18c0b4a.tar.gz
busybox-w32-cccdc4e01abb354c50aa483a21d5ff56a18c0b4a.tar.bz2
busybox-w32-cccdc4e01abb354c50aa483a21d5ff56a18c0b4a.zip
hush: fix $ expansion in redirections, add testcase for that
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 04afbfd9a..912cbb5d9 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1361,8 +1361,11 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
1361 continue; 1361 continue;
1362 } 1362 }
1363 if (redir->dup == -1) { 1363 if (redir->dup == -1) {
1364 char *p;
1364 mode = redir_table[redir->type].mode; 1365 mode = redir_table[redir->type].mode;
1365 openfd = open_or_warn(redir->glob_word[0], mode); 1366 p = expand_string_to_string(redir->glob_word[0]);
1367 openfd = open_or_warn(p, mode);
1368 free(p);
1366 if (openfd < 0) { 1369 if (openfd < 0) {
1367 /* this could get lost if stderr has been redirected, but 1370 /* this could get lost if stderr has been redirected, but
1368 bash and ash both lose it as well (though zsh doesn't!) */ 1371 bash and ash both lose it as well (though zsh doesn't!) */
@@ -2579,7 +2582,7 @@ static int expand_vars_to_list(char **list, int n, char **posp, char *arg, char
2579 } 2582 }
2580 } else 2583 } else
2581 /* If or_mask is nonzero, we handle assignment 'a=....$@.....' 2584 /* If or_mask is nonzero, we handle assignment 'a=....$@.....'
2582 * and in this case should theat it like '$*' */ 2585 * and in this case should treat it like '$*' - see 'else...' below */
2583 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */ 2586 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */
2584 while (1) { 2587 while (1) {
2585 strcpy(pos, global_argv[i]); 2588 strcpy(pos, global_argv[i]);
@@ -2593,10 +2596,10 @@ static int expand_vars_to_list(char **list, int n, char **posp, char *arg, char
2593 list[n++] = pos; 2596 list[n++] = pos;
2594 } 2597 }
2595 } else { /* quoted $*: add as one word */ 2598 } else { /* quoted $*: add as one word */
2596 while (1) { 2599 if (global_argv[i]) while (1) {
2597 strcpy(pos, global_argv[i]); 2600 strcpy(pos, global_argv[i]);
2598 pos += strlen(global_argv[i]); 2601 pos += strlen(global_argv[i]);
2599 if (++i >= global_argc) 2602 if (!global_argv[++i])
2600 break; 2603 break;
2601 if (ifs[0]) 2604 if (ifs[0])
2602 *pos++ = ifs[0]; 2605 *pos++ = ifs[0];