1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

Restore #22 'unset -f' fix minus segfault (re: b7932e87, 97511748)

Applying the fix for 'unset -f' exposed a crashing bug in lookup()
in sh/nvdisc.c, which is the function for looking up discipline
functions. This is what caused tests/variables.sh to crash.
Ref.: https://github.com/ksh93/ksh/issues/23#issuecomment-645699614

src/cmd/ksh93/sh/nvdisc.c: lookup():
- To avoid segfault, check that the function pointer nq->nvalue.rp
  is actually set before checking if nq->nvalue.rp->running==1.

src/cmd/ksh93/sh/xec.c,
src/cmd/ksh93/tests/functions.sh:
- Uncomment the 'unset -f' fix from b7932e87.

Resolves #21 (again).
This commit is contained in:
Martijn Dekker 2020-06-18 02:48:51 +02:00
parent 975117485c
commit 3e3f6b0f12
4 changed files with 9 additions and 8 deletions

8
NEWS
View file

@ -3,6 +3,14 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs.
2020-06-17:
- A bug in 'unset -f' was fixed that prevented shell functions from
unsetting themselves while they were running. A POSIX function no longer
crashes when doing so, and a KornShell-style function no longer silently
ignores an 'unset -f' on itself. A function of either form now continues
running after unsetting itself, and is removed at the end of the run.
2020-06-16:
- Passing the '-d' flag to the read builtin will no longer cause the '-r'

View file

@ -417,7 +417,7 @@ static char* lookup(Namval_t *np, int type, Sfdouble_t *dp,Namfun_t *handle)
}
if(bp== &block)
block_done(bp);
if(nq && nq->nvalue.rp->running==1)
if(nq && nq->nvalue.rp && nq->nvalue.rp->running==1)
{
nq->nvalue.rp->running=0;
_nv_unset(nq,0);

View file

@ -3505,16 +3505,11 @@ static void sh_funct(Shell_t *shp,Namval_t *np,int argn, char *argv[],struct arg
nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE);
shp->pipepid = pipepid;
np->nvalue.rp->running -= 2;
/*
* TODO: fix https://github.com/ksh93/ksh/issues/21
* Following causes a memory fault in: bin/shtests -p variables
*
if(np->nvalue.rp && np->nvalue.rp->running==1)
{
np->nvalue.rp->running = 0;
_nv_unset(np, NV_RDONLY);
}
*/
}
/*

View file

@ -1253,12 +1253,10 @@ expect_status=0
# When a function unsets itself, it should not fail to be unset
$SHELL -c 'PATH=/dev/null; fn() { unset -f fn; true; }; fn' || err_exit 'unset of POSIX function in the calling stack fails'
$SHELL -c 'PATH=/dev/null; function ftest { ftest2; }; function ftest2 { unset -f ftest; }; ftest' || err_exit 'unset of ksh function in the calling stack fails'
: <<\end_disabled # TODO: re-enable when https://github.com/ksh93/ksh/issues/21 is fixed
$SHELL -c 'PATH=/dev/null; fn() { unset -f fn; true; }; fn; fn' 2> /dev/null
[[ $? != 127 ]] && err_exit 'unset of POSIX function fails when it is still running'
$SHELL -c 'PATH=/dev/null; function fn { unset -f fn; true; }; fn; fn' 2> /dev/null
[[ $? != 127 ]] && err_exit 'unset of ksh function fails when it is still running'
end_disabled
# ======
exit $((Errors<125?Errors:125))