1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Fix restoring DEBUG trap upon exiting virtual subshell

This trap failed to be restored correctly when being trapped in
a subshell, causing corruption or a crash when restoring the
parent shell environment's trap upon leaving the subshell.

Thanks to Koichi Nakashima for the report and reproducer.

src/cmd/ksh93/sh/fault.c: sh_sigreset():
- Fix an off-by-one error in the loop that restores the
  pseudosignal traps.

src/cmd/ksh93/tests/basic.sh:
- Test overwriting the main shell trap in a subshell for all
  pseudosignals.

Makes progress on: https://github.com/ksh93/ksh/issues/155
This commit is contained in:
Martijn Dekker 2021-01-24 00:49:36 +00:00
parent ac8e702ef2
commit 2a835a2d8a
4 changed files with 23 additions and 2 deletions

5
NEWS
View file

@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs. Any uppercase BUG_* names are modernish shell bug IDs.
2021-01-23:
- Fixed: when the DEBUG trap was redefined in a subshell, the DEBUG trap in
the parent environment was corrupted or the shell crashed.
2021-01-22: 2021-01-22:
- Compile-time shell options can now be edited in src/cmd/ksh93/SHOPT.sh - Compile-time shell options can now be edited in src/cmd/ksh93/SHOPT.sh

View file

@ -20,7 +20,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */ #define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2021-01-20" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_DATE "2021-01-23" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK #define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -344,7 +344,7 @@ void sh_sigreset(register int mode)
sh.sigflag[sig] = flag; sh.sigflag[sig] = flag;
} }
} }
for(sig=SH_DEBUGTRAP-1;sig>=0;sig--) for(sig=SH_DEBUGTRAP; sig>=0; sig--)
{ {
if(trap=sh.st.trap[sig]) if(trap=sh.st.trap[sig])
{ {

View file

@ -744,6 +744,22 @@ got=$(eval 'x=${ for i in test; do case $i in test) true;; esac; done; }' 2>&1)
got=$(eval 'x=`for i in test; do case $i in test) true;; esac; done`' 2>&1) \ got=$(eval 'x=`for i in test; do case $i in test) true;; esac; done`' 2>&1) \
|| err_exit "case in a for loop inside a \`comsub\` caused syntax error (got $(printf %q "$got"))" || err_exit "case in a for loop inside a \`comsub\` caused syntax error (got $(printf %q "$got"))"
# ======
# The DEBUG trap crashed when re-trapping inside a subshell
# https://github.com/ksh93/ksh/issues/155 (#2)
exp=$'trap -- \': main\' EXIT\ntrap -- \': main\' ERR\ntrap -- \': main\' KEYBD\ntrap -- \': main\' DEBUG'
got=$({ "$SHELL" -c '
PATH=/dev/null
for sig in EXIT ERR KEYBD DEBUG
do trap ": main" $sig
( trap ": LEAK : $sig" $sig )
trap
trap - "$sig"
done
'; } 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'Pseudosignal trap failed when re-trapping in subshell' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
# ====== # ======
# The DEBUG trap had side effects on the exit status # The DEBUG trap had side effects on the exit status
# https://github.com/ksh93/ksh/issues/155 (#4) # https://github.com/ksh93/ksh/issues/155 (#4)