1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/sh
Johnothan King 7b994b6a7e Implement a better fix for unsetting special env vars
The regression this commit fixes was first introduced in ksh93t
2008-07-25. It was previously worked around in 6f0e008c by forking
subshells if any special environment variable is unset.

The reason why this problem doesn't occur in ksh93s+ is because in
that version of ksh sh_assignok never moves nodes, it only clones
them. The second argument doesn't set NV_MOVE, which makes
`sh_assignok(np,0)` is similar to `sh_assignok(np,1)`. In ksh93t and
higher, setting the second argument to zero causes the node to be moved
with NV_MOVE, which causes the discipline function associated with
the variable node to be removed when `np->nvfun` is set to zero (i.e.
NULL). This is why a command like `(unset LC_NUMERIC; LC_NUMERIC=invalid)`
doesn't print a diagnostic, as it looses its discipline function.

This patch fixes the problem by cloning the node with sh_assignok
if it is a special variable with a discipline function. This allows
special variables to work as expected in virtual subshells. The
original workaround has been kept for the $PATH variable only, as
hash tables are still broken in virtual subshells. It has been updated
accordingly to only fork subshells if it detects the variable node
for PATH. I have added two more regression tests for changing the
PATH in subshells to make sure hash tables continue working as
expected with this fix.

src/cmd/ksh93/bltins/typeset.c:
 - Only fork virtual subshells if the PATH will be changed. If a
   variable is a special variable with a discipline function, it
   should be just be cloned, not moved.

src/cmd/ksh93/sh/nvdisc.c:
 - Add a comment to clarify that NV_MOVE will delete the discipline
   function associated with the node.

src/cmd/ksh93/tests/subshells.sh:
 - Add two more regression tests for unsetting the PATH in subshells,
   one for if PATH is being pointed to by a nameref. Condense the
   hash table tests by moving the main test into a single function.
2020-06-13 12:55:48 -07:00
..
args.c Fix set +r so that it cannot unset the restricted option 2020-06-12 01:45:18 +02:00
arith.c Fix 'test'/'[' exit status >1 on error in arithmetic expression 2020-06-12 01:45:15 +02:00
array.c Fix 80 typos in comments 2020-06-12 01:45:12 +02:00
bash.c Fix 47 typos in user-facing help and error messages 2020-06-12 01:45:12 +02:00
defs.c Fix 'test'/'[' exit status >1 on error in arithmetic expression 2020-06-12 01:45:15 +02:00
deparse.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
env.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
expand.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
fault.c Fix signal handling due to exit status > 256 2020-06-12 01:45:17 +02:00
fcin.c Fix parsing of multibyte characters 2020-06-12 01:45:17 +02:00
init.c Refactor new b_hash(); better hash table clear (re: d8428a83) 2020-06-12 01:45:18 +02:00
io.c Remove code related to long-dead 3DFS research project 2020-06-12 01:45:17 +02:00
jobs.c Remove code related to long-dead 3DFS research project 2020-06-12 01:45:17 +02:00
lex.c Fix BUG_REDIRIO 2020-06-12 01:45:13 +02:00
macro.c POSIX compliance fix: apply 'set -u' to $! 2020-06-12 01:45:17 +02:00
main.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
name.c Refactor new b_hash(); better hash table clear (re: d8428a83) 2020-06-12 01:45:18 +02:00
nvdisc.c Implement a better fix for unsetting special env vars 2020-06-13 12:55:48 -07:00
nvtree.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
nvtype.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
parse.c Fix memory corruption while parsing functions 2020-06-12 01:45:16 +02:00
path.c Remove code related to long-dead 3DFS research project 2020-06-12 01:45:17 +02:00
pmain.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
shcomp.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
streval.c Fix 'test'/'[' exit status >1 on error in arithmetic expression 2020-06-12 01:45:15 +02:00
string.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
subshell.c Fix ${.sh.subshell} counter to actually count level of subshells 2020-06-12 01:45:16 +02:00
suid_exec.c Fix 39 spelling errors and a formatting issue 2020-06-12 01:45:18 +02:00
tdump.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
timers.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
trestore.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
waitevent.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
xec.c Remove 'login' and 'newgrp' builtins: not sane default behaviour 2020-06-12 06:57:57 +02:00