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

do not save file desc state for subshares (re: 6304dfce, fb755163)

The >&- redirection subshell leak fixed in 6304dfce still existed
for shared-state ${ command substitutions; } a.k.a. subshares,
which cannot be forked.

I previously noticed that sh_subsavefd() saves the FD state even
for subshares. That seems logically incorrect as subshares share
their state with the invoking environment by definition.

src/cmd/ksh93/sh/subshell.c: sh_subsavefd():
- Sure enough, adding a check for !sh.subshare fixes the bug.
- Use the sh.subshell counter and not the subshell data pointer to
  check for a virtual subshell. If the shell is reinitialised in a
  fork to execute a new script (see 0af81992), any parent virtual
  subshell data is currently not cleared as it is locally scoped to
  subshell.c, so that check would be incorrect then.

src/cmd/ksh93/sh/io.c: sh_redirect:
- Remove now-redundant (and actually incorrectly placed) check for
  sh.subshare added in fb755163.
This commit is contained in:
Martijn Dekker 2022-02-11 03:17:45 +00:00
parent 6304dfce41
commit 1cdd963f53
3 changed files with 9 additions and 2 deletions

View file

@ -1468,7 +1468,7 @@ int sh_redirect(struct ionod *iop, int flag)
}
else if(sh_subsavefd(fn))
{
if(fd==fn && !sh.subshare)
if(fd==fn)
{
if((r=sh_fcntl(fd,F_DUPFD,10)) > 0)
{