mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix subshell leak for 4 special variables (re: bd3e2a80)
The following special variables leaked out of a subshell:
$_, ${.sh.name}, ${.sh.level}, ${.sh.subscript}.
This was due to a faulty optimisation in sh_assignok().
bd3e2a80 fixed that in part, this fixes the rest.
src/cmd/ksh93/sh/subshell.c:
- Simplify sh_assignok() by removing special-casing for these four
special variables. The 'add' param reverts to a simple boolean.
- The test for a ${ subshare; } was actually wrong. sp->subshare is
a saved backup value. We must test shp->subshare. (re: a9de50bf)
src/cmd/ksh93/bltins/typeset.c:
- setall(), unall(): Update sh_assignok() calls.
src/cmd/ksh93/tests/variables.sh:
- Regress-test subshell leaks for all special variables.
Closes: #122
This commit is contained in:
parent
00d439605f
commit
b3d37b00b0
3 changed files with 19 additions and 12 deletions
|
|
@ -1011,6 +1011,20 @@ $SHELL -c '
|
|||
e=$?
|
||||
((e == 1)) || err_exit "Failure in making one or more special variables readonly in a subshell (exit status $e)"
|
||||
|
||||
# ... subshell leak test
|
||||
$SHELL -c '
|
||||
errors=0
|
||||
for var
|
||||
do if eval "($var=bug); [[ \${$var} == bug ]]" 2>/dev/null
|
||||
then echo " $0: special variable $var leaks out of subshell" >&2
|
||||
let errors++
|
||||
fi
|
||||
done
|
||||
exit $((errors + 1))
|
||||
' subshell_leak_test "$@"
|
||||
e=$?
|
||||
((e == 1)) || err_exit "One or more special variables leak out of a subshell (exit status $e)"
|
||||
|
||||
# ======
|
||||
# ${.sh.pid} should be the forked subshell's PID
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue