Skip to content

Commit 5135cf6

Browse files
authored
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.
1 parent c870be9 commit 5135cf6

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
33

44
Any uppercase BUG_* names are modernish shell bug IDs.
55

6+
2020-06-28:
7+
8+
- Variables created with 'typeset -RF' no longer cause a memory fault
9+
when accessed.
10+
611
2020-06-26:
712

813
- Changing to a directory that has a name starting with a '.' will no

src/cmd/ksh93/include/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* David Korn <dgk@research.att.com> *
1818
* *
1919
***********************************************************************/
20-
#define SH_RELEASE "93u+m 2020-06-26"
20+
#define SH_RELEASE "93u+m 2020-06-28"

src/cmd/ksh93/sh/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static char *array_getval(Namval_t *np, Namfun_t *disc)
578578
return(cp);
579579
}
580580
#if SHOPT_FIXEDARRAY
581-
if(ap->fixed && nv_isattr(np,NV_INT16P) == NV_INT16)
581+
if(ap->fixed && nv_isattr(np,NV_INT16P|NV_DOUBLE) == NV_INT16)
582582
np->nvalue.s = *np->nvalue.sp;
583583
#endif /* SHOPT_FIXEDARRAY */
584584
return(nv_getv(np,&ap->hdr));

src/cmd/ksh93/sh/name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
16481648
return;
16491649
}
16501650
up= &np->nvalue;
1651-
if(nv_isattr(np,NV_INT16P) == NV_INT16)
1651+
if(nv_isattr(np,NV_INT16P|NV_DOUBLE) == NV_INT16)
16521652
{
16531653
if(!np->nvalue.up || !nv_isarray(np))
16541654
{

src/cmd/ksh93/sh/nvdisc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static void *num_clone(register Namval_t *np, void *val)
862862
size = sizeof(Sflong_t);
863863
else if(nv_isattr(np,NV_SHORT))
864864
{
865-
if(nv_isattr(np,NV_INT16P)==NV_INT16P)
865+
if(nv_isattr(np,NV_INT16P|NV_DOUBLE)==NV_INT16P)
866866
size = sizeof(short);
867867
else
868868
return((void*)np->nvalue.ip);

src/cmd/ksh93/tests/types.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,4 +645,9 @@ Bar_t bar
645645
bar.foo+=(bam)
646646
[[ ${bar.foo[0]} == bam ]] || err_exit 'appending to empty array variable in type does not create element 0'
647647
648+
# ======
649+
# 'typeset -RF' should not create variables that cause crashes
650+
"$SHELL" -c 'typeset -RF foo=1; test $foo' || err_exit 'typeset -RF does not work'
651+
652+
# ======
648653
exit $((Errors<125?Errors:125))

0 commit comments

Comments
 (0)