summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko2007-05-09 22:16:08 +0000
committerDenis Vlasenko2007-05-09 22:16:08 +0000
commit2b54aaa9bf38eedc3c35604e19ae5415f6e9f2df (patch)
tree6aeaadbb6c72bfe66f4c620e2c556d84c9ced318
parent389f9d52d5520dea157fab474caacf3d8b1bde73 (diff)
downloadbusybox-2b54aaa9bf38eedc3c35604e19ae5415f6e9f2df.zip
busybox-2b54aaa9bf38eedc3c35604e19ae5415f6e9f2df.tar.gz
msh: fix obscure case with backticks and closed fd 1
-rw-r--r--shell/msh.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/shell/msh.c b/shell/msh.c
index 4feede6..ac49af1 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -2546,7 +2546,7 @@ static int execute(struct op *t, int *pin, int *pout, int act)
interactive = 0;
if (pin == NULL) {
close(0);
- open(bb_dev_null, O_RDONLY);
+ xopen(bb_dev_null, O_RDONLY);
}
_exit(execute(t->left, pin, pout, FEXEC));
}
@@ -2823,12 +2823,12 @@ static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
#endif
if (pin != NULL) {
- dup2(pin[0], 0);
- closepipe(pin);
+ xmove_fd(pin[0], 0);
+ if (pin[1] != 0) close(pin[1]);
}
if (pout != NULL) {
- dup2(pout[1], 1);
- closepipe(pout);
+ xmove_fd(pout[1], 1);
+ if (pout[1] != 1) close(pout[0]);
}
iopp = t->ioact;
@@ -4166,8 +4166,13 @@ static int grave(int quoted)
if (ourtrap[j] && signal(j, SIG_IGN) != SIG_IGN)
signal(j, SIG_DFL);
- dup2(pf[1], 1);
- closepipe(pf);
+ /* Testcase where below checks are needed:
+ * close stdout & run this script:
+ * files=`ls`
+ * echo "$files" >zz
+ */
+ xmove_fd(pf[1], 1);
+ if (pf[0] != 1) close(pf[0]);
argument_list[0] = (char *) DEFAULT_SHELL;
argument_list[1] = (char *) "-c";