From 544754df6ff92ef2dbf542e1928e0de4f7e18559 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sat, 6 Mar 2010 17:09:22 +0000 Subject: [PATCH] sh: Make sure to popredir() even if a special builtin caused an error. --- bin/sh/eval.c | 5 +++-- tools/regression/bin/sh/builtins/command9.0 | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tools/regression/bin/sh/builtins/command9.0 diff --git a/bin/sh/eval.c b/bin/sh/eval.c index c0a7601a6165..b1de3065b4be 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -914,6 +914,9 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) backcmd->nleft = memout.nextc - memout.buf; memout.buf = NULL; } + if (cmdentry.u.index != EXECCMD && + (e == -1 || e == EXERROR || e == EXEXEC)) + popredir(); if (e != -1) { if ((e != EXERROR && e != EXEXEC) || cmdentry.special) @@ -922,8 +925,6 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) if (flags != EV_BACKCMD) FORCEINTON; } - if (cmdentry.u.index != EXECCMD) - popredir(); } else { #ifdef DEBUG trputs("normal command: "); trargs(argv); diff --git a/tools/regression/bin/sh/builtins/command9.0 b/tools/regression/bin/sh/builtins/command9.0 new file mode 100644 index 000000000000..212e52aafc98 --- /dev/null +++ b/tools/regression/bin/sh/builtins/command9.0 @@ -0,0 +1,14 @@ +# $FreeBSD$ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$({ command eval shift x 2>/dev/null; } >/dev/null; echo hi)" = hi' + +exit $((failures > 0))