Skip to content

Commit

Permalink
Fix exporting vars in subshells
Browse files Browse the repository at this point in the history
This change applies the fix from here:

https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/250-22561374.patch

It also adds a regression test.

Fixes #7
  • Loading branch information
krader1961 committed Nov 11, 2017
1 parent 8659ddc commit c26719b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/cmd/ksh93/sh/subshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ Namval_t *sh_assignok(register Namval_t *np,int add)
return(np);
shp = sp->shp;
dp = shp->var_tree;
/* don't bother to save if in newer scope */
if(sp->var!=shp->var_tree && sp->var!=shp->var_base && shp->last_root==shp->var_tree)
return(np);

if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np)))
{
shp->last_root = ap->table;
Expand Down
30 changes: 30 additions & 0 deletions src/cmd/ksh93/tests/subshell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,34 @@ then (( size = 117*1024 ))
fi
fi

# ========================================
# Test that variables exported in subshells don't affect the outer shell.
# Regression test for issue #7.
function proxy {
export MYVAR="blah"
child
unset MYVAR
}

function child {
echo "MYVAR=$MYVAR"
}

function test {
child
proxy
child
}

actual="$(test)"
expected="\
MYVAR=
MYVAR=blah
MYVAR="
if [[ $actual != $expected ]]
then
err_exit -u2 "exported vars in subshells not confined to the subshell: $actual"
fi

# ========================================
exit $((Errors<125?Errors:125))

0 comments on commit c26719b

Please sign in to comment.