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

Correct memory fault when removing default nameref KSH_VERSION (#271)

This commit fixes a segmentation fault when an attempt was made to
unset the default KSH_VERSION variable prior any other nameref
activity such as creating another nameref or even reassigning the
nameref KSH_VERSION to something else.

(new shell without prior nameref activity)
$ nameref
KSH_VERSION=.sh.version
$ unset -n KSH_VERSION
Memory fault

src/cmd/ksh93/sh/name.c: _nv_unset():
- Add a 'Refdict' check before attempting to remove a value from it
  as apparently one does not exist until some sort of nameref
  activity occurs after shell startup as the default nameref of
  'KSH_VERSION=.sh.version' does not create one.
This commit is contained in:
hyenias 2021-04-12 22:15:34 -04:00 committed by GitHub
parent 75796a9c75
commit d6ddd89053
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View file

@ -2578,7 +2578,7 @@ void _nv_unset(register Namval_t *np,int flags)
else if(nv_isref(np) && !nv_isattr(np,NV_EXPORT|NV_MINIMAL) && np->nvalue.nrp)
{
if(np->nvalue.nrp->root)
if(np->nvalue.nrp->root && Refdict)
dtdelete(Refdict,(void*)np->nvalue.nrp);
if(np->nvalue.nrp->sub)
free(np->nvalue.nrp->sub);