1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 03:32:24 +00:00

Fix process substitutions printing PIDs in profile scripts (#395)

- sh/args.c: A process substitution run in a profile script may print
  its PID as if it was a command spawned with '&'. Reproducer:
     $ cat /tmp/env
     true >(false)
     $ ENV=/tmp/env ksh
     [1]	730227
     $
  This bug is fixed by turning off the SH_PROFILE state while running
  a process substitution.

- sh/subshell.c: The SH_INTERACTIVE fix in 3525535e renders the extra
  check for SH_PROFILE redundant, so it has been removed.

- tests/io.sh: Update the procsub PIDs test to also check the result
  after using process substitution in a profile script.
This commit is contained in:
Johnothan King 2021-12-22 05:25:26 -08:00 committed by Martijn Dekker
parent 740a24a456
commit 3785a0685c
5 changed files with 13 additions and 6 deletions

5
NEWS
View file

@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs.
2021-12-22:
- Process substitutions run in a profile script no longer print their
process ID when run.
2021-12-21:
- Fixed a bug that caused subshells (such as code blocks in parentheses) to

View file

@ -21,7 +21,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2021-12-21" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2021-12-22" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -761,6 +761,7 @@ struct argnod *sh_argprocsub(Shell_t *shp,struct argnod *argp)
/* turn off job control */
sh_offstate(SH_INTERACTIVE);
sh_offstate(SH_MONITOR);
sh_offstate(SH_PROFILE);
job.jobcontrol = 0;
/* run the process substitution */
shp->subshell = 0;

View file

@ -666,7 +666,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
{
if(comsub)
sigblock(SIGTSTP);
else if(!sh_isstate(SH_PROFILE))
else
sh_subfork();
}
#endif

View file

@ -590,10 +590,11 @@ result=$("$SHELL" -c 'echo ok > >(sed s/ok/good/); wait' 2>&1)
[[ $result == good ]] || err_exit 'process substitution does not work with redirections' \
"(expected 'good', got $(printf %q "$result"))"
# Process substitution in an interactive shell shouldn't print the
# process ID of the asynchronous process.
result=$("$SHELL" -ic 'echo >(true) >/dev/null' 2>&1)
[[ -z $result ]] || err_exit 'interactive shells print a PID during process substitution' \
# Process substitution in an interactive shell or profile script shouldn't
# print the process ID of the asynchronous process.
echo 'false >(false)' > "$tmp/procsub-envtest"
result=$(ENV=$tmp/procsub-envtest "$SHELL" -ic 'true >(true)' 2>&1)
[[ -z $result ]] || err_exit 'interactive shells and/or profile scripts print a PID during process substitution' \
"(expected '', got $(printf %q "$result"))"
# ======