Consider the following test case:

{ while IFS='' read -r L; do echo 1; done < <(echo line; echo line) ; } 
>tmpout.txt; echo xyz;

or:

{ { :; } < <(:) ; } >tmpout.txt; echo xyz;

"xyz" doesn't get printed to stdout; instead it gets printed to
tmpout.txt, for `evaltree` only does `popredir`, not considering
the possibility of a process substitution.

This patch fixes it by changing it to `unwindredir`.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes
---
 shell/ash.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index 841ffe880..4cf95f8ae 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9519,7 +9519,8 @@ evaltree(union node *n, int flags)
        case NNOT:
                status = !evaltree(n->nnot.com, EV_TESTED);
                break;
-       case NREDIR:
+       case NREDIR: {
+               struct redirtab *redir_stop = redirlist;
                errlinno = lineno = n->nredir.linno;
                expredir(n->nredir.redirect);
                pushredir(n->nredir.redirect);
@@ -9527,9 +9528,9 @@ evaltree(union node *n, int flags)
                if (!status) {
                        status = evaltree(n->nredir.n, flags & EV_TESTED);
                }
-               if (n->nredir.redirect)
-                       popredir(/*drop:*/ 0);
+               unwindredir(redir_stop);
                break;
+       }
        case NCMD:
                evalfn = evalcommand;
  checkexit:
-- 
2.51.0

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to