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

Fix I/O redirection in -c script (Solaris patch 280-23332860)

This change is pulled from here:
https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/280-23332860.patch

Info and reproducers:
https://github.com/att/ast/issues/36

In a -c script (like ksh -c 'commands'), the last command
misredirects standard output if an EXIT or ERR trap is set.
This appears to be a side effect of the optimisation that
runs the last command without forking.

This applies a patch by George Lijo that flags these specific
cases and disables the optimisation.

src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/bltins/trap.c,
src/cmd/ksh93/sh/init.c,
src/cmd/ksh93/sh/main.c,
src/cmd/ksh93/sh/xec.c:
- Apply patch as above.

src/cmd/ksh93/tests/io.sh:
- Add the reproducers from the bug report as regression tests.
This commit is contained in:
Martijn Dekker 2021-01-08 14:06:34 +00:00
parent 7c47ab56fe
commit 17ebfbf6a3
6 changed files with 78 additions and 1 deletions

View file

@ -1479,6 +1479,9 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
#endif
if(shp->userinit=userinit)
(*userinit)(shp, 0);
shp->exittrap = 0;
shp->errtrap = 0;
shp->end_fn = 0;
return(shp);
}
@ -1580,6 +1583,9 @@ int sh_reinit(char *argv[])
shp->inpipe = shp->outpipe = 0;
job_clear();
job.in_critical = 0;
shp->exittrap = 0;
shp->errtrap = 0;
shp->end_fn = 0;
/* update ${.sh.pid}, $$, $PPID */
shgd->current_pid = shgd->pid = getpid();
shgd->ppid = getppid();