-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax errors in ~/.kshrc
cause ksh to exit on startup
#281
Comments
~/.kshrc
cause ksh to exit on startup
Thanks for finding the commits that introduced these, that made it much easier. Please try this: --- a/src/cmd/ksh93/sh/lex.c
+++ b/src/cmd/ksh93/sh/lex.c
@@ -2060,6 +2060,7 @@ static char *fmttoken(Lex_t *lp, register int sym)
return((char*)sh_translate(e_endoffile));
if(sym==NL)
return((char*)sh_translate(e_newline));
+ stakfreeze(0);
stakputc(sym);
if(sym&SYMREP)
stakputc(sym);
--- a/src/cmd/ksh93/sh/main.c
+++ b/src/cmd/ksh93/sh/main.c
@@ -424,7 +424,7 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno)
sfsync(shp->outpool);
shp->st.execbrk = shp->st.breakcnt = 0;
/* check for return from profile or env file */
- if(sh_isstate(SH_PROFILE) && (jmpval==SH_JMPFUN || jmpval==SH_JMPEXIT || jmpval==SH_JMPERREXIT))
+ if(sh_isstate(SH_PROFILE) && (jmpval==SH_JMPFUN || jmpval==SH_JMPEXIT) || !sh_isstate(SH_PROFILE) && jmpval==SH_JMPERREXIT)
{
sh_setstate(states);
goto done;
@@ -603,7 +603,7 @@ done:
}
if(jmpval == SH_JMPSCRIPT)
siglongjmp(*shp->jmplist,jmpval);
- else if(jmpval == SH_JMPEXIT || jmpval == SH_JMPERREXIT)
+ else if(jmpval == SH_JMPEXIT || !sh_isstate(SH_PROFILE) && jmpval == SH_JMPERREXIT)
sh_done(shp,0);
if(fno>0)
sh_close(fno); |
I can confirm the new patch fixes both of the regressions. |
It looks like the patch will need some more work. I've ran it against the regression tests and got these two failures:
|
Commit ceb77b1 is meant to fix rhbz#1212992. The reproducer for the bug is in comment 3. I've tried it against ksh93u+ and it crashes (as expected), but even when I revert Red Hat's patch it seems to work just fine in ksh93u+m. # Note: Both tests below are run with vmalloc
# ksh93u+
$ LD_PRELOAD=/home/johno/Downloads/write.so valgrind ksh93u -l
Memory fault # After loops invoking sh_assignok()
# ksh93u+m, with the diskfull patch reverted
$ LD_PRELOAD=/home/johno/Downloads/write.so valgrind arch/*/bin/ksh -l
==8324== Memcheck, a memory error detector
==8324== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8324== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==8324== Command: arch/linux.i386-64/bin/ksh -l
==8324==
$ Possibly the diskfull patch is no longer necessary? I'll trace which commit fixed the memory fault. |
I've found that commit 970069a is what fixed the memory fault. Additionally, I've tested Red Hat's patch against ksh93u+ (and ksh93u+m with the aforementioned commit reverted) and on my system the diskfull patch doesn't fix the crash at all. So, unless I'm missing something I believe the best way to fix this bug is to revert the broken diskfull patch. New diff below (all the regression tests pass, including Red Hat's reproducer): --- a/src/cmd/ksh93/sh/lex.c
+++ b/src/cmd/ksh93/sh/lex.c
@@ -2060,6 +2060,7 @@ static char *fmttoken(Lex_t *lp, register int sym)
return((char*)sh_translate(e_endoffile));
if(sym==NL)
return((char*)sh_translate(e_newline));
+ stakfreeze(0);
stakputc(sym);
if(sym&SYMREP)
stakputc(sym);
--- a/src/cmd/ksh93/sh/main.c
+++ b/src/cmd/ksh93/sh/main.c
@@ -424,7 +424,7 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno)
sfsync(shp->outpool);
shp->st.execbrk = shp->st.breakcnt = 0;
/* check for return from profile or env file */
- if(sh_isstate(SH_PROFILE) && (jmpval==SH_JMPFUN || jmpval==SH_JMPEXIT || jmpval==SH_JMPERREXIT))
+ if(sh_isstate(SH_PROFILE) && (jmpval==SH_JMPFUN || jmpval==SH_JMPEXIT))
{
sh_setstate(states);
goto done;
@@ -603,7 +603,7 @@ done:
}
if(jmpval == SH_JMPSCRIPT)
siglongjmp(*shp->jmplist,jmpval);
- else if(jmpval == SH_JMPEXIT || jmpval == SH_JMPERREXIT)
+ else if(jmpval == SH_JMPEXIT)
sh_done(shp,0);
if(fno>0)
sh_close(fno); |
FWIW, on the Mac, the test fails like this:
Thanks for doing the testing and figuring out that the diskfull patch should be reverted. Your results make sense to me and I'm happy to take your word for it. |
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: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.
The text was updated successfully, but these errors were encountered: