summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-06 17:56:09 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-06 17:56:09 +0000
commit817e73cb63282b61d6944dcb2b10bde4326bfcbb (patch)
tree31d5005f9be0b7f1b64701ee56bcb6697f80a972 /shell/hush.c
parent12422ffe3eb9a27f40a0e8dfd003010c374b7593 (diff)
downloadbusybox-w32-817e73cb63282b61d6944dcb2b10bde4326bfcbb.tar.gz
busybox-w32-817e73cb63282b61d6944dcb2b10bde4326bfcbb.tar.bz2
busybox-w32-817e73cb63282b61d6944dcb2b10bde4326bfcbb.zip
A patch from Larry to fix pathological things like '>""'
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index a58da189c..126f9da89 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -997,6 +997,10 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
997 struct redir_struct *redir; 997 struct redir_struct *redir;
998 998
999 for (redir=prog->redirects; redir; redir=redir->next) { 999 for (redir=prog->redirects; redir; redir=redir->next) {
1000 if (redir->dup == -1 && redir->word.gl_pathv == NULL) {
1001 /* something went wrong in the parse. Pretend it didn't happen */
1002 continue;
1003 }
1000 if (redir->dup == -1) { 1004 if (redir->dup == -1) {
1001 mode=redir_table[redir->type].mode; 1005 mode=redir_table[redir->type].mode;
1002 openfd = open(redir->word.gl_pathv[0], mode, 0666); 1006 openfd = open(redir->word.gl_pathv[0], mode, 0666);
@@ -1545,8 +1549,11 @@ static int free_pipe(struct pipe *pi, int indent)
1545 for (r=child->redirects; r; r=rnext) { 1549 for (r=child->redirects; r; r=rnext) {
1546 final_printf("%s redirect %d%s", ind, r->fd, redir_table[r->type].descrip); 1550 final_printf("%s redirect %d%s", ind, r->fd, redir_table[r->type].descrip);
1547 if (r->dup == -1) { 1551 if (r->dup == -1) {
1548 final_printf(" %s\n", *r->word.gl_pathv); 1552 /* guard against the case >$FOO, where foo is unset or blank */
1549 globfree(&r->word); 1553 if (r->word.gl_pathv) {
1554 final_printf(" %s\n", *r->word.gl_pathv);
1555 globfree(&r->word);
1556 }
1550 } else { 1557 } else {
1551 final_printf("&%d\n", r->dup); 1558 final_printf("&%d\n", r->dup);
1552 } 1559 }
@@ -1599,10 +1606,10 @@ static int run_list(struct pipe *pi)
1599 */ 1606 */
1600static int globhack(const char *src, int flags, glob_t *pglob) 1607static int globhack(const char *src, int flags, glob_t *pglob)
1601{ 1608{
1602 int cnt, pathc; 1609 int cnt=0, pathc;
1603 const char *s; 1610 const char *s;
1604 char *dest; 1611 char *dest;
1605 for (cnt=1, s=src; *s; s++) { 1612 for (cnt=1, s=src; s && *s; s++) {
1606 if (*s == '\\') s++; 1613 if (*s == '\\') s++;
1607 cnt++; 1614 cnt++;
1608 } 1615 }
@@ -1619,7 +1626,7 @@ static int globhack(const char *src, int flags, glob_t *pglob)
1619 if (pglob->gl_pathv == NULL) return GLOB_NOSPACE; 1626 if (pglob->gl_pathv == NULL) return GLOB_NOSPACE;
1620 pglob->gl_pathv[pathc-1]=dest; 1627 pglob->gl_pathv[pathc-1]=dest;
1621 pglob->gl_pathv[pathc]=NULL; 1628 pglob->gl_pathv[pathc]=NULL;
1622 for (s=src; *s; s++, dest++) { 1629 for (s=src; s && *s; s++, dest++) {
1623 if (*s == '\\') s++; 1630 if (*s == '\\') s++;
1624 *dest = *s; 1631 *dest = *s;
1625 } 1632 }
@@ -1829,6 +1836,7 @@ static int setup_redirect(struct p_context *ctx, int fd, redir_type style,
1829 } 1836 }
1830 redir = xmalloc(sizeof(struct redir_struct)); 1837 redir = xmalloc(sizeof(struct redir_struct));
1831 redir->next=NULL; 1838 redir->next=NULL;
1839 redir->word.gl_pathv=NULL;
1832 if (last_redir) { 1840 if (last_redir) {
1833 last_redir->next=redir; 1841 last_redir->next=redir;
1834 } else { 1842 } else {