cdesktopenv/src/cmd/ksh93/sh
Johnothan King 3d38270b32 Remove a buggy optimization for variables in subshells
This bug was originally reported by @lijog in att/ast#7 and has been
reported again in #15. KSH does not save the state of a variable if it
is in a newer scope. This is because of an optimization in sh_assignok
first introduced in ksh93t+ 2010-05-24. Here is the code change in that
version:

                return(np);
        /* don't bother to save if in newer scope */
-       if(!(rp=shp->st.real_fun)  || !(dp=rp->sdict))
-               dp = sp->var;
-       if(np->nvenv && !nv_isattr(np,NV_MINIMAL|NV_EXPORT) && shp->last_root)
-               dp = shp->last_root;
-       if((mp=nv_search((char*)np,dp,HASH_BUCKET))!=np)
-       {
-               if(mp || !np->nvfun || np->nvfun->subshell>=sh.subshell)
-                       return(np);
-       }
+       if(sp->var!=shp->var_tree && shp->last_root==shp->var_tree)
+               return(np);
        if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np)))
        {

This change was originally made to replace a buggier optimization.
However, the current optimization causes variables set in subshells
to wrongly affect the environment outside of the subshell, as the
variable does not get set back to its original value. This patch
simply removes the buggy optimization to fix this problem.

src/cmd/ksh93/sh/subshell.c:
 - Remove a buggy optimization that caused variables set in subshells
   to affect the environment outside of the subshell.

src/cmd/ksh93/tests/subshell.sh:
 - Add a regression test for setting variables in subshells. This
   test has to be run from the disk after being created with a here
   document because it always returns the expected result when run
   directly in the regression test script.
2020-06-15 07:13:38 -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 Make 'source' a regular built-in 2020-06-15 11:33:44 +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 Remove a buggy optimization for variables in subshells 2020-06-15 07:13:38 -07: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