fix running the ERR and EXIT traps in case of set -e and/or eval (includes Debian #696823)
This commit is contained in:
27
main.c
27
main.c
@ -5,7 +5,7 @@
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
* 2011, 2012
|
||||
* 2011, 2012, 2013
|
||||
* Thorsten Glaser <tg@mirbsd.org>
|
||||
*
|
||||
* Provided that these terms and disclaimer and all copyright notices
|
||||
@ -34,7 +34,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.249 2012/12/17 23:18:07 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.250 2013/01/01 20:45:03 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -873,18 +873,35 @@ void
|
||||
unwind(int i)
|
||||
{
|
||||
/* ordering for EXIT vs ERR is a bit odd (this is what AT&T ksh does) */
|
||||
if (i == LEXIT || (Flag(FERREXIT) && (i == LERROR || i == LINTR) &&
|
||||
sigtraps[ksh_SIGEXIT].trap)) {
|
||||
if (i == LEXIT || (Flag(FERREXIT) == 1 &&
|
||||
(i == LERROR || i == LINTR) && sigtraps[ksh_SIGEXIT].trap)) {
|
||||
++trap_nested;
|
||||
runtrap(&sigtraps[ksh_SIGEXIT], trap_nested == 1);
|
||||
--trap_nested;
|
||||
i = LLEAVE;
|
||||
} else if (Flag(FERREXIT) && (i == LERROR || i == LINTR)) {
|
||||
} else if (Flag(FERREXIT) == 1 && (i == LERROR || i == LINTR)) {
|
||||
++trap_nested;
|
||||
runtrap(&sigtraps[ksh_SIGERR], trap_nested == 1);
|
||||
--trap_nested;
|
||||
i = LLEAVE;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a kludge. We need to restore everything that was
|
||||
* changed in the new environment, see cid 1005090337C7A669439
|
||||
* and 10050903386452ACBF1, but fail to even save things most of
|
||||
* the time. funcs.c:c_eval() changes FERREXIT temporarily to 0,
|
||||
* which needs to be restored thus (related to Debian #696823).
|
||||
* We did not save the shell flags, so we use a special or'd
|
||||
* value here... this is mostly to clean up behind *other*
|
||||
* callers of unwind(LERROR) here; exec.c has the regular case.
|
||||
*/
|
||||
if (Flag(FERREXIT) & 0x80) {
|
||||
/* GNU bash does not run this trapsig */
|
||||
trapsig(ksh_SIGERR);
|
||||
Flag(FERREXIT) &= ~0x80;
|
||||
}
|
||||
|
||||
while (/* CONSTCOND */ 1) {
|
||||
switch (e->type) {
|
||||
case E_PARSE:
|
||||
|
Reference in New Issue
Block a user