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

Fix crashes caused by 'typeset -RF' (#47)

Variables created with 'typeset -RF' were being treated as
short integers, even though they are actually floating point
values. As a result the following example will cause a crash:

$ typeset -RF foo=1
$ test "$foo"

This is fixed by checking for 'NV_DOUBLE' with 'nv_isattr',
which prevents ksh from treating floating point values as
short integers due to '== NV_INT16P' excluding 'NV_DOUBLE'.
This bugfix was backported from ksh93v- 2013-10-10-alpha.

src/cmd/ksh93/sh/array.c,
src/cmd/ksh93/sh/name.c,
src/cmd/ksh93/sh/nvdisc:
- Avoid treating floating point values as short integers by
  checking for 'NV_DOUBLE' with 'nv_isattr'.

src/cmd/ksh93/tests/types.sh:
- Add a regression test for the 'typeset -RF' crash. The
  crash cannot be replicated if 'typeset -RF' sets 'foo'
  to zero.
This commit is contained in:
Johnothan King 2020-06-28 15:30:27 -07:00 committed by GitHub
parent c870be9fea
commit 5135cf651c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 4 deletions

View file

@ -578,7 +578,7 @@ static char *array_getval(Namval_t *np, Namfun_t *disc)
return(cp);
}
#if SHOPT_FIXEDARRAY
if(ap->fixed && nv_isattr(np,NV_INT16P) == NV_INT16)
if(ap->fixed && nv_isattr(np,NV_INT16P|NV_DOUBLE) == NV_INT16)
np->nvalue.s = *np->nvalue.sp;
#endif /* SHOPT_FIXEDARRAY */
return(nv_getv(np,&ap->hdr));