mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix unreliable behavior when special vars are readonly or unset (#27)
src/cmd/ksh93/data/variables.c:
- Running 'unset .sh.lineno' creates a memory fault, so fix that
by giving it the NV_NOFREE attribute. This crash was happening
because ${.sh.lineno} is an integer that cannot be freed from
memory with free(3).
src/cmd/ksh93/sh/init.c:
- Tell _nv_unset to ignore NV_RDONLY when $RANDOM and $LINENO are
restored from the subshell scope. This is required to fully
restore the original state of these variables after a virtual
subshell finishes.
src/cmd/ksh93/bltins/typeset.c,
src/cmd/ksh93/sh/subshell.c:
- Disabled some optimizations for two instances of 'sh_assignok' to
fix 'readonly' in virtual subshells and '(unset .sh.level)' in
nested functions. This fixes the following variables when
'(readonly $varname); enum varname=' is run:
$_
${.sh.name}
${.sh.subscript}
${.sh.level}
The optimization in question prevents sh_assignok from saving the
original state of these variables by making the sh_assignok call
a no-op. Ksh needs the original state of a variable for it to be
properly restored after a virtual subshell has run, otherwise ksh
will simply carry over any new flags (being NV_RDONLY in this case)
from the subshell into the main shell.
src/cmd/ksh93/tests/variables.sh:
- Add regression tests from Martijn Dekker for setting special
variables as readonly in virtual subshells and for unsetting
special variables in general.
Fixes #4
This commit is contained in:
parent
ee698e89d5
commit
bd3e2a8001
7 changed files with 174 additions and 9 deletions
15
NEWS
15
NEWS
|
|
@ -3,6 +3,21 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2020-06-20:
|
||||
|
||||
- Fixed a bug that caused setting the following variables as readonly in
|
||||
a virtual subshell to affect the environment outside of the subshell:
|
||||
$_
|
||||
${.sh.name}
|
||||
${.sh.subscript}
|
||||
${.sh.level}
|
||||
$RANDOM
|
||||
$LINENO
|
||||
|
||||
- Fixed two bugs that caused `unset .sh.lineno` to always produce a memory
|
||||
fault and `(unset .sh.level)` to memory fault when run in nested
|
||||
functions.
|
||||
|
||||
2020-06-18:
|
||||
|
||||
- A two decade old bug that caused 'whence -a' to base the path of
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue