summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-03-06 17:31:09 +0000
committerjilles <jilles@FreeBSD.org>2010-03-06 17:31:09 +0000
commit3242a81cf43fb6016f65673c693e101d491d0e6a (patch)
tree19870d344864f5031127af5c39f2a3ff00900053
parentc30671a949eb9683bebf9a37cc4e35a46fde00d9 (diff)
downloadFreeBSD-src-3242a81cf43fb6016f65673c693e101d491d0e6a.zip
FreeBSD-src-3242a81cf43fb6016f65673c693e101d491d0e6a.tar.gz
sh: Make sure to popredir() even if a function caused an error.
-rw-r--r--bin/sh/eval.c4
-rw-r--r--tools/regression/bin/sh/builtins/command10.014
2 files changed, 17 insertions, 1 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index b1de306..cdd6386 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -813,7 +813,6 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
#ifdef DEBUG
trputs("Shell function: "); trargs(argv);
#endif
- redirect(cmd->ncmd.redirect, REDIR_PUSH);
saveparam = shellparam;
shellparam.malloc = 0;
shellparam.reset = 1;
@@ -831,6 +830,8 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
else {
freeparam(&shellparam);
shellparam = saveparam;
+ if (exception == EXERROR || exception == EXEXEC)
+ popredir();
}
unreffunc(cmdentry.u.func);
poplocalvars();
@@ -841,6 +842,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
}
handler = &jmploc;
funcnest++;
+ redirect(cmd->ncmd.redirect, REDIR_PUSH);
INTON;
for (sp = varlist.list ; sp ; sp = sp->next)
mklocal(sp->text);
diff --git a/tools/regression/bin/sh/builtins/command10.0 b/tools/regression/bin/sh/builtins/command10.0
new file mode 100644
index 0000000..2c1adf1
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/command10.0
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ if ! eval "[ $* ]"; then
+ echo "Failed: $*"
+ : $((failures += 1))
+ fi
+}
+
+check '"$(f() { shift x; }; { command eval f 2>/dev/null; } >/dev/null; echo hi)" = hi'
+
+exit $((failures > 0))
OpenPOWER on IntegriCloud