mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix subshell file descriptor leak
A file descriptor (at least 3, can't reproduce for 4 and up) opened with 'exec' or 'redirect' in a virtual/non-forked subshell survived that subshell after exiting it: $ ksh -c '(redirect 3>&1); echo bug >&3' bug src/cmd/ksh93/sh/io.c: - Apply a patch from OpenSUSE (ksh93-redirectleak.dif). Source: https://build.opensuse.org/package/show/openSUSE:Leap:42.3:Update/ksh src/cmd/ksh93/tests/io.sh: - Add regression test. Thanks to Marc Wilson for flagging this up.
This commit is contained in:
parent
0c96f9749b
commit
db72f41f4b
3 changed files with 23 additions and 0 deletions
|
@ -567,5 +567,15 @@ result=$("$SHELL" -ic 'echo >(true) >/dev/null' 2>&1)
|
|||
"$SHELL" -c 'true 9>&20000000000000000000' 2> /dev/null
|
||||
[[ $? == 1 ]] || err_exit "Out of range file descriptors cause redirections to segfault"
|
||||
|
||||
# ======
|
||||
# A file descriptor opened with 'exec' or 'redirect' leaked out of a subshell.
|
||||
exec 3>&- # close FD 3 just in case
|
||||
(exec 3>"$tmp/fdleak.txt")
|
||||
{ echo bug >&3; } 2>/dev/null
|
||||
if [[ -s "$tmp/fdleak.txt" ]]
|
||||
then exec 3>&-
|
||||
err_exit "Open file descriptor leaks out of subshell"
|
||||
fi
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue