-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
variable exported in function in a subshell is also visible in a different subshell #7
Comments
Does anyone know why the proposed fix hasn't been merged? I can reproduce the failure using the provided test case using a ksh93 built from the current |
The patch is nearly impossible to read. Please use markdown to denote code blocks (to avoid interpreting code as markdown and to switch font to monospace). |
I just edited the comment to format the code blocks. |
@dannyweldon Thanks! I do not have privileges to do it myself... @krader1961 The proposed patch makes sense to me. It fixes the problem and does no seem to break anything else... |
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
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
Since we now have a shiny new POSIX compliant 'times' builtin, we might as well use it. src/cmd/ksh93/tests/shtests: - Run 'times' at end of test run. - Skip the pretty-printing until #7 is fixed. (cherry picked from commit 2c27d9fbc239583004ec70377db98627eea5e294)
Since we now have a shiny new POSIX compliant 'times' builtin, we might as well use it. src/cmd/ksh93/tests/shtests: - Run 'times' at end of test run. - Skip the pretty-printing until #7 is fixed. (cherry picked from commit 2c27d9fbc239583004ec70377db98627eea5e294)
This bug was originally reported by @lijog in att#7 and has been reported again in ksh93#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 in a here document because it always returns the expected result when run directly in the regression test script.
This bug was originally reported by @lijog in att#7 and has been reported again in ksh93#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 in a here document because it always returns the expected result when run directly in the regression test script.
This bug was originally reported by @lijog in att#7 and has been reported again in ksh93#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.
ksh 93u+ has a subshell leak bug where a variable exported in function in a subshell is also visible in a different subshell. This is long fixed in 93u+m, but there wasn't a regression test for this particular bug yet, so this commit adds one.
Implement a better fix for unsetting special env vars. See att#7 for more explanations and ksh source code history :)
I've observed this issue in a Solaris 11 system with all the ksh93 versions(alpha, beta and the master versions) as well as in Ubuntu 14 ( ksh2012).
Here's a testcase which reproduces the issue.
The following patch which removes an optimization fixes the issue. If there is any other patch, please let me know.
The issue seems to be happening because of the following optimization in sh_assignok function in sh/subshell.c.
This optimization prevents saving the variables in situations where they don't need to be restored. If we remove the optimization, the issue will go away.
The text was updated successfully, but these errors were encountered: