aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-02 14:17:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-02 14:17:31 +0200
commit1dd6cf867754030223fadd0f4d959039f713bfb1 (patch)
tree66d78ab21de9cdfaa4d66f90d63c15a5e04fd046 /shell
parent54e0843e7dabc4f6d79781f8b07094dadacd4cd5 (diff)
downloadbusybox-w32-1dd6cf867754030223fadd0f4d959039f713bfb1.tar.gz
busybox-w32-1dd6cf867754030223fadd0f4d959039f713bfb1.tar.bz2
busybox-w32-1dd6cf867754030223fadd0f4d959039f713bfb1.zip
hush: fix multiple redirections of the same fd (bug 227)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c8
-rw-r--r--shell/hush_test/hush-misc/redir6.right4
-rwxr-xr-xshell/hush_test/hush-misc/redir6.tests5
3 files changed, 15 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c
index cbec2dd71..5daca960c 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2646,7 +2646,9 @@ static int setup_redirects(struct command *prog, int squirrel[])
2646 for (redir = prog->redirects; redir; redir = redir->next) { 2646 for (redir = prog->redirects; redir; redir = redir->next) {
2647 if (redir->rd_type == REDIRECT_HEREDOC2) { 2647 if (redir->rd_type == REDIRECT_HEREDOC2) {
2648 /* rd_fd<<HERE case */ 2648 /* rd_fd<<HERE case */
2649 if (squirrel && redir->rd_fd < 3) { 2649 if (squirrel && redir->rd_fd < 3
2650 && squirrel[redir->rd_fd] < 0
2651 ) {
2650 squirrel[redir->rd_fd] = dup(redir->rd_fd); 2652 squirrel[redir->rd_fd] = dup(redir->rd_fd);
2651 } 2653 }
2652 /* for REDIRECT_HEREDOC2, rd_filename holds _contents_ 2654 /* for REDIRECT_HEREDOC2, rd_filename holds _contents_
@@ -2682,7 +2684,9 @@ static int setup_redirects(struct command *prog, int squirrel[])
2682 } 2684 }
2683 2685
2684 if (openfd != redir->rd_fd) { 2686 if (openfd != redir->rd_fd) {
2685 if (squirrel && redir->rd_fd < 3) { 2687 if (squirrel && redir->rd_fd < 3
2688 && squirrel[redir->rd_fd] < 0
2689 ) {
2686 squirrel[redir->rd_fd] = dup(redir->rd_fd); 2690 squirrel[redir->rd_fd] = dup(redir->rd_fd);
2687 } 2691 }
2688 if (openfd == REDIRFD_CLOSE) { 2692 if (openfd == REDIRFD_CLOSE) {
diff --git a/shell/hush_test/hush-misc/redir6.right b/shell/hush_test/hush-misc/redir6.right
new file mode 100644
index 000000000..a97c4bdf1
--- /dev/null
+++ b/shell/hush_test/hush-misc/redir6.right
@@ -0,0 +1,4 @@
1Testing multiple redirections to same fd
2Hello
3Done1
4Done2
diff --git a/shell/hush_test/hush-misc/redir6.tests b/shell/hush_test/hush-misc/redir6.tests
new file mode 100755
index 000000000..c639ebb2d
--- /dev/null
+++ b/shell/hush_test/hush-misc/redir6.tests
@@ -0,0 +1,5 @@
1echo "Testing multiple redirections to same fd"
2# bug was making us lose fd #1 after this:
3echo Hello >/dev/null 1>&2
4echo Done1
5echo Done2 >&2