defer setting exstat for eval to 0 (the one used in case shell() is empty)

until after the stuff run in shell() has had a chance to toy with $?

bug forwarded by one of our packagers, found by one of their users
This commit is contained in:
tg 2012-10-21 21:55:05 +00:00
parent 31f24a4040
commit c7419d9e6a
3 changed files with 25 additions and 8 deletions

18
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.560 2012/10/21 17:38:22 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.561 2012/10/21 21:55:01 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R40 2012/10/03 @(#)MIRBSD KSH R40 2012/10/21
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R40 2012/10/03 @(#)LEGACY KSH R40 2012/10/21
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:
@ -5748,19 +5748,29 @@ name: exit-eval-1
description: description:
Check eval vs substitution exit codes (ksh93 alike) Check eval vs substitution exit codes (ksh93 alike)
stdin: stdin:
(exit 12)
eval $(false) eval $(false)
echo A $? echo A $?
(exit 12)
eval ' $(false)' eval ' $(false)'
echo B $? echo B $?
(exit 12)
eval " $(false)" eval " $(false)"
echo C $? echo C $?
(exit 12)
eval "eval $(false)" eval "eval $(false)"
echo D $? echo D $?
(exit 12)
eval 'eval '"$(false)" eval 'eval '"$(false)"
echo E $? echo E $?
IFS="$IFS:" IFS="$IFS:"
(exit 12)
eval $(echo :; false) eval $(echo :; false)
echo F $? echo F $?
echo -n "G "
(exit 12)
eval 'echo $?'
echo H $?
expected-stdout: expected-stdout:
A 0 A 0
B 1 B 1
@ -5768,6 +5778,8 @@ expected-stdout:
D 0 D 0
E 0 E 0
F 0 F 0
G 12
H 0
--- ---
name: exit-trap-1 name: exit-trap-1
description: description:

11
funcs.c
View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.227 2012/10/21 21:39:02 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.228 2012/10/21 21:55:03 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -2210,8 +2210,10 @@ c_eval(const char **wp)
* If there are no arguments, or only null arguments, * If there are no arguments, or only null arguments,
* eval shall return a zero exit status; ... * eval shall return a zero exit status; ...
*/ */
/* exstat = subst_exstat; */ /* AT&T ksh88 */ /* AT&T ksh88: use subst_exstat */
exstat = 0; /* SUSv4 */ /* exstat = subst_exstat; */
/* SUSv4: OR with a high value never written otherwise */
exstat |= 0x4000;
savef = Flag(FERREXIT); savef = Flag(FERREXIT);
Flag(FERREXIT) = 0; Flag(FERREXIT) = 0;
@ -2219,6 +2221,9 @@ c_eval(const char **wp)
Flag(FERREXIT) = savef; Flag(FERREXIT) = savef;
source = saves; source = saves;
afree(s, ATEMP); afree(s, ATEMP);
if (exstat & 0x4000)
/* detect old exstat, use 0 in that case */
rv = 0;
return (rv); return (rv);
} }

4
sh.h
View File

@ -157,9 +157,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.594 2012/10/21 21:39:05 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.595 2012/10/21 21:55:05 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2012/10/03" #define MKSH_VERSION "R40 2012/10/21"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES