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

Fix v=$(<file) for closed FD 0,1,2 (rhbz#1066589)

var=$(< file) now reads the file even if the standard inout,
standard output and/or standard error file descriptors are closed.

Original patch:
https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-filecomsubst.patch

src/cmd/ksh93/sh/io.c: sh_redirect():
- When processing the '<' redirector as part of $(< ...), i.e. if
  flag==3, make sure the FD of the file to read is > 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.
This commit is contained in:
Martijn Dekker 2020-09-22 02:45:59 +02:00
parent 5683155cb5
commit fe6d0903dc
3 changed files with 6 additions and 0 deletions

3
NEWS
View file

@ -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 to lose the output of the commands they ran. This bug occurred when ksh was
compiled with the SHOPT_SPAWN compile-time option. 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: 2020-09-20:
- Bugfix: when whence -v/-a found an "undefined" (i.e. autoloadable) function - Bugfix: when whence -v/-a found an "undefined" (i.e. autoloadable) function

View file

@ -1266,6 +1266,8 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
if(flag==SH_SHOWME) if(flag==SH_SHOWME)
goto traceit; goto traceit;
fd=sh_chkopen(fname); fd=sh_chkopen(fname);
if(flag==3) /* make sure that $(<file) works... */
fd=sh_iomovefd(fd); /* ...with stdin/stdout/stderr closed */
} }
else if(sh_isoption(SH_RESTRICTED)) else if(sh_isoption(SH_RESTRICTED))
errormsg(SH_DICT,ERROR_exit(1),e_restricted,fname); errormsg(SH_DICT,ERROR_exit(1),e_restricted,fname);

View file

@ -462,6 +462,7 @@ got=$(<$tmp/22.out)
tmp=$tmp $SHELL 2> /dev/null -c 'exec 3<&1 ; exec 1<&- ; exec > $tmp/outfile;print foobar' || err_exit 'exec 1<&- causes failure' tmp=$tmp $SHELL 2> /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 ]] || err_exit 'outfile does not contain foobar'
[[ $(<$tmp/outfile) == foobar ]] <&- >&- 2>&- || err_exit '$(<file) does not work with stdin, stdout and/or stderr closed'
print hello there world > $tmp/foobar print hello there world > $tmp/foobar
sed -e 's/there //' $tmp/foobar >; $tmp/foobar sed -e 's/there //' $tmp/foobar >; $tmp/foobar