Skip to content

Commit b7dde4e

Browse files
McDutchieJohnoKing
andcommitted
Fix ksh exit on syntax error in profile (re: cb67a01, ceb77b1)
Johnothan King writes: > There are two regressions related to how ksh handles syntax > errors in the .kshrc file. If ~/.kshrc or the file pointed to by > $ENV have a syntax error, ksh exits during startup. Additionally, > the error message printed is incorrect: > > $ cat /tmp/synerror > (( > echo foo > > # ksh93u+m > $ ENV=/tmp/synerror arch/*/bin/ksh -ic 'echo ${.sh.version}' > /tmp/synerror: syntax error: `/t/tmp/synerror' unmatched > > # ksh93u+ > $ ENV=/tmp/synerror ksh93u -ic 'echo ${.sh.version}' > /tmp/synerror: syntax error: `(' unmatched > Version AJM 93u+ 2012-08-01 > > The regression that causes the incorrect error message was > introduced by commit cb67a01. The other bug that causes ksh to > exit on startup was introduced by commit ceb77b1. src/cmd/ksh93/sh/lex.c: fmttoken(): - Call stakfreeze(0) to terminate a possible unterminated previous stack item before writing the token string onto the stack. This fixes the bug with garbage in a syntax error message. src/cmd/ksh93/sh/main.c: exfile(): - Revert Red Hat's ksh-20140801-diskfull.patch applied in ceb77b1. This fixes the bug with interactive ksh exiting on syntax error in a profile script. Testing by @JohnoKing showed the patch is no longer necessary to fix a login crash on disk full, as commit 970069a (which applied Red Hat patches ksh-20120801-macro.patch and ksh-20120801-fd2lost.patch) also fixes that crash. src/cmd/ksh93/README: - Fix typos. (re: fdc08b2) Co-authored-by: Johnothan King Resolves: #281
1 parent fdc08b2 commit b7dde4e

6 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎NEWS‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
33

44
Any uppercase BUG_* names are modernish shell bug IDs.
55

6+
2021-04-21:
7+
8+
- Fixed a bug introduced on 2020-09-28 that caused an interactive ksh to exit
9+
if a profile script (such as ~/.kshrc) contains a syntax error.
10+
611
2021-04-20:
712

813
- Fixed three problems with the /opt/ast/bin/getconf built-in command:

‎src/cmd/ksh93/README‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The options have the following defaults and meanings:
4444
built-ins. The value must include double quotes.
4545
CRNL off treated as in shell grammar.
4646
DEVFD Use the more secure /dev/fd mechanism instead of FIFOs for
47-
proces substitutions. On by default on OSs with /dev/fd.
47+
process substitutions. On by default on OSs with /dev/fd.
4848
DYNAMIC on Dynamic loading of builtins. (Requires dlopen() interface.)
4949
ECHOPRINT off Make echo equivalent to print.
5050
EDPREDICT on Enables predictive editing. As you type a line beginning
@@ -84,7 +84,7 @@ The options have the following defaults and meanings:
8484
value will require the -p flag to run suid/sgid scripts.
8585
RAWONLY on Turn on if the vi line mode doesn't work right unless
8686
you do a set -o viraw.
87-
REGRESS off Enable the __regress__ built-in command and instrumented
87+
REGRESS off Enable the __regress__ built-in command and instrumented
8888
intercepts for testing.
8989
REMOTE off Set --rc (read profile scripts) even if ksh was invoked
9090
with standard input on a socket, i.e. as a remote shell.

‎src/cmd/ksh93/include/version.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
2222
#define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */
23-
#define SH_RELEASE_DATE "2021-04-20" /* must be in this format for $((.sh.version)) */
23+
#define SH_RELEASE_DATE "2021-04-21" /* must be in this format for $((.sh.version)) */
2424
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
2525

2626
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

‎src/cmd/ksh93/sh/lex.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,7 @@ static char *fmttoken(Lex_t *lp, register int sym)
20602060
return((char*)sh_translate(e_endoffile));
20612061
if(sym==NL)
20622062
return((char*)sh_translate(e_newline));
2063+
stakfreeze(0);
20632064
stakputc(sym);
20642065
if(sym&SYMREP)
20652066
stakputc(sym);

‎src/cmd/ksh93/sh/main.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno)
424424
sfsync(shp->outpool);
425425
shp->st.execbrk = shp->st.breakcnt = 0;
426426
/* check for return from profile or env file */
427-
if(sh_isstate(SH_PROFILE) && (jmpval==SH_JMPFUN || jmpval==SH_JMPEXIT || jmpval==SH_JMPERREXIT))
427+
if(sh_isstate(SH_PROFILE) && (jmpval==SH_JMPFUN || jmpval==SH_JMPEXIT))
428428
{
429429
sh_setstate(states);
430430
goto done;
@@ -603,7 +603,7 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno)
603603
}
604604
if(jmpval == SH_JMPSCRIPT)
605605
siglongjmp(*shp->jmplist,jmpval);
606-
else if(jmpval == SH_JMPEXIT || jmpval == SH_JMPERREXIT)
606+
else if(jmpval == SH_JMPEXIT)
607607
sh_done(shp,0);
608608
if(fno>0)
609609
sh_close(fno);

‎src/cmd/ksh93/tests/pty.sh‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,5 +797,19 @@ w cd emacste\t123abc
797797
r ^:test-1: cd emacstest/123abc\r\n$
798798
!
799799

800+
# err_exit #
801+
echo '((' >$tmp/synerror
802+
ENV=$tmp/synerror tst $LINENO <<"!"
803+
L syntax error in profile causes exit on startup
804+
# https://github.com/ksh93/ksh/issues/281
805+
806+
d 15
807+
r /synerror: syntax error: `\(' unmatched\r\n$
808+
p :test-1:
809+
w echo ok
810+
r ^:test-1: echo ok\r\n$
811+
r ^ok\r\n$
812+
!
813+
800814
# ======
801815
exit $((Errors<125?Errors:125))

0 commit comments

Comments
 (0)