1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Don't detect unset functions with whence (re: 13c57e4b) (#287)

src/cmd/ksh93/bltins/whence.c:
- The previous commit that fixed 'unset -f' in virtual subshells left
  one bug. The type builtin (or 'whence -v') could still find the unset
  function in virtual subshells:
    $ foo() { echo foo; }
    $ (unset -f foo; type foo)
    foo is an undefined function
  To fix this bug, avoid detecting functions in the whence builtin
  unless they have the NV_FUNCTION flag.

src/cmd/ksh93/tests/subshell.sh:
- Add a regression test for using 'type' on a function unset inside of
  a virtual subshell.
This commit is contained in:
Johnothan King 2021-04-24 13:25:45 -07:00 committed by GitHub
parent 07faf38425
commit 24b7fcb771
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -192,7 +192,7 @@ static int whence(Shell_t *shp,char **argv, register int flags)
}
/* built-ins and functions next */
bltins:
if(!(flags&F_FLAG) && (np = nv_bfsearch(name, shp->fun_tree, &nq, &notused)) && !is_abuiltin(np))
if(!(flags&F_FLAG) && (np = nv_bfsearch(name, shp->fun_tree, &nq, &notused)) && is_afunction(np))
{
if(flags&Q_FLAG)
continue;

View file

@ -699,6 +699,16 @@ got=$( f() { echo WRONG; }; ( unset -f f; PATH=/dev/null f 2>&1 ) )
[[ $got == $exp ]] || err_exit 'unset -f fails in sub-subshell on function set in subshell' \
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
# Functions unset in a subshell shouldn't be detected by type (whence -v)
# https://github.com/ksh93/ksh/pull/287
notafunc() {
echo 'Failure'
}
exp=Success
got=$(unset -f notafunc; type notafunc 2>/dev/null || echo Success)
[[ $got == "$exp" ]] || err_exit "type/whence -v finds function in virtual subshell after it's unset with 'unset -f'" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# Unsetting or redefining aliases within subshells