summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko2009-05-02 14:17:31 +0200
committerDenys Vlasenko2009-05-02 14:17:31 +0200
commit1dd6cf867754030223fadd0f4d959039f713bfb1 (patch)
tree66d78ab21de9cdfaa4d66f90d63c15a5e04fd046 /shell/hush.c
parent54e0843e7dabc4f6d79781f8b07094dadacd4cd5 (diff)
downloadbusybox-1dd6cf867754030223fadd0f4d959039f713bfb1.zip
busybox-1dd6cf867754030223fadd0f4d959039f713bfb1.tar.gz
hush: fix multiple redirections of the same fd (bug 227)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c
index cbec2dd..5daca96 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2646,7 +2646,9 @@ static int setup_redirects(struct command *prog, int squirrel[])
for (redir = prog->redirects; redir; redir = redir->next) {
if (redir->rd_type == REDIRECT_HEREDOC2) {
/* rd_fd<<HERE case */
- if (squirrel && redir->rd_fd < 3) {
+ if (squirrel && redir->rd_fd < 3
+ && squirrel[redir->rd_fd] < 0
+ ) {
squirrel[redir->rd_fd] = dup(redir->rd_fd);
}
/* for REDIRECT_HEREDOC2, rd_filename holds _contents_
@@ -2682,7 +2684,9 @@ static int setup_redirects(struct command *prog, int squirrel[])
}
if (openfd != redir->rd_fd) {
- if (squirrel && redir->rd_fd < 3) {
+ if (squirrel && redir->rd_fd < 3
+ && squirrel[redir->rd_fd] < 0
+ ) {
squirrel[redir->rd_fd] = dup(redir->rd_fd);
}
if (openfd == REDIRFD_CLOSE) {