From 975117485c9c52a2d94bcf1eb7ae7f44088a3302 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 17 Jun 2020 21:01:55 +0200 Subject: [PATCH] Part revert #22 to undo memory fault (re: b7932e87) The fix in sh/xec.c, which was backported from the ksh 93v- beta to delay the actual removal of a running function that unsets itself, caused a segfault in the variables.sh regression tests (see #23). src/cmd/ksh93/sh/xec.c: - Comment out the backported code pending a correct fix for #21. Now both types of functions silently fail to unset themselves (unless they're discipline functions). src/cmd/ksh93/tests/functions.sh: - Disable regression tests checking that the function was actually unset, pending a correct fix for #21. Resolves: #23 Reopens: #21 --- NEWS | 9 --------- src/cmd/ksh93/sh/xec.c | 5 +++++ src/cmd/ksh93/tests/functions.sh | 2 ++ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 110ed872e..28dc7a2c5 100644 --- a/NEWS +++ b/NEWS @@ -3,15 +3,6 @@ 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 POSIX function that unsets itself while it is running no longer causes - a segmentation fault. - -- `unset -f` no longer silently fails when a KornShell style function tries - to unset itself while it is running. The function will now be unset once - it has finished running. - 2020-06-16: - Passing the '-d' flag to the read builtin will no longer cause the '-r' diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 6bb4355eb..d2e660820 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -3505,11 +3505,16 @@ 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); } +*/ } /* diff --git a/src/cmd/ksh93/tests/functions.sh b/src/cmd/ksh93/tests/functions.sh index ca51e026d..7b081027c 100755 --- a/src/cmd/ksh93/tests/functions.sh +++ b/src/cmd/ksh93/tests/functions.sh @@ -1253,10 +1253,12 @@ 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))