1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix erroneous fork after 'readonly PATH' in subshell (re: 102868f8)

After making PATH readonly in a virtual subshell (without otherwise
changing it, so the subshell is never forked), then the main shell
would erroneously fork into a background process immediately after
leaving the virtual subshell. This was caused by a bug in the
forking workaround that prevents changes in PATH in a virtual
subshell from clearing the parent shell's hash table.

src/cmd/ksh93/sh/name.c: nv_putval():
- If we're either setting or restoring PATH, do an additional check
  for the NV_RDONLY flag, which means the function was told to
  ignore the variable's readonly state. It is told to ignore that
  when restoring the parent shell state after exiting a virtual
  subshell. If we don't fork then, we don't fork the parent shell.

src/cmd/ksh93/tests/subshell.sh:
- Add regression test verifying that no forking happens when making
  PATH readonly in a subshell.

Fixes #30.
This commit is contained in:
Martijn Dekker 2020-06-20 23:39:42 +02:00
parent bd3e2a8001
commit 9d428f8f5e
2 changed files with 18 additions and 1 deletions

View file

@ -1609,8 +1609,11 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
/*
* Resetting the PATH in a non-forking subshell will reset the parent shell's
* hash table, so work around the problem by forking before sh_assignok
* -- however, don't do this if we were told to ignore the variable's readonly state (i.e.
* if the NV_RDONLY flag is set), because that means we're restoring the parent shell state
* after exiting a virtual subshell, and we would end up forking the parent shell instead.
*/
if(shp->subshell && !shp->subshare && np == PATHNOD)
if(np == PATHNOD && !(flags & NV_RDONLY) && shp->subshell && !shp->subshare)
sh_subfork();
/*