From fe6d0903dc5a6d6af3e72fc1d0da72e2c9db6751 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 22 Sep 2020 02:45:59 +0200 Subject: [PATCH] Fix v=$( 2 by calling sh_iomovefd(). Unlike the RedHat patch, this checks for flag==3 to avoid unnecessary sh_iomovefd() calls for normal redirections, as there was no bug with those. src/cmd/ksh93/tests/io.sh: - Add test. --- NEWS | 3 +++ src/cmd/ksh93/sh/io.c | 2 ++ src/cmd/ksh93/tests/io.sh | 1 + 3 files changed, 6 insertions(+) diff --git a/NEWS b/NEWS index 0340d645f..a9f32164b 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. to lose the output of the commands they ran. This bug occurred when ksh was compiled with the SHOPT_SPAWN compile-time option. +- Bugfix: var=$(< file) now reads the file even if the standard inout, standard + output and/or standard error file descriptors are closed. + 2020-09-20: - Bugfix: when whence -v/-a found an "undefined" (i.e. autoloadable) function diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index 4c7ef034d..b3e18171e 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -1266,6 +1266,8 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag) if(flag==SH_SHOWME) goto traceit; fd=sh_chkopen(fname); + if(flag==3) /* make sure that $( /dev/null -c 'exec 3<&1 ; exec 1<&- ; exec > $tmp/outfile;print foobar' || err_exit 'exec 1<&- causes failure' [[ $(<$tmp/outfile) == foobar ]] || err_exit 'outfile does not contain foobar' +[[ $(<$tmp/outfile) == foobar ]] <&- >&- 2>&- || err_exit '$( $tmp/foobar sed -e 's/there //' $tmp/foobar >; $tmp/foobar