diff --git a/NEWS b/NEWS index d0fbee9e3..5c28ac7ae 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Fixed a crash, introduced on 2021-01-19, that occurred when using 'cd' in a subshell with the PWD variable unset. +- Fixed a crash that could occur when or after entering the suspend character + (Ctrl+Z) while the shell was blocked trying to write to a FIFO special file. + 2022-01-16: - Backported minor additions to the 'read' built-in command from ksh 93v-: diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c index f5c4ee4c2..1ae545160 100644 --- a/src/cmd/ksh93/sh/fault.c +++ b/src/cmd/ksh93/sh/fault.c @@ -181,15 +181,15 @@ void sh_fault(register int sig) sh.lastsig = sig; flag = SH_SIGSET; #ifdef SIGTSTP - if(sig==SIGTSTP) + if(sig==SIGTSTP && pp->mode==SH_JMPCMD) { - sh.trapnote |= SH_SIGTSTP; - if(pp->mode==SH_JMPCMD && sh_isstate(SH_STOPOK)) + if(sh_isstate(SH_STOPOK)) { + sh.trapnote |= SH_SIGTSTP; sigrelease(sig); sh_exit(SH_EXITSIG); - return; } + return; } #endif /* SIGTSTP */ } diff --git a/src/cmd/ksh93/tests/pty.sh b/src/cmd/ksh93/tests/pty.sh index 06f316bb1..aed6a2662 100755 --- a/src/cmd/ksh93/tests/pty.sh +++ b/src/cmd/ksh93/tests/pty.sh @@ -977,5 +977,26 @@ r !99 r : !99: event not found\r\n$ ! +mkfifo testfifo +tst $LINENO <<"!" +L suspend a blocked write to a FIFO +# https://github.com/ksh93/ksh/issues/464 + +d 15 +p :test-1: +w echo >testfifo +r echo +# untrapped SIGTSTP (Ctrl+Z) should be ineffective here and just print ^Z +c \cZ +r ^\^Z$ +# Ctrl+C should interrupt it and trigger an error message +c \cC +r ^\^C.*: testfifo: cannot create \[.*\]\r\n$ +p :test-2: +w echo ok +r echo +r ^ok\r\n$ +! + # ====== exit $((Errors<125?Errors:125))