1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Fix crash when listing indexed arrays with 'typeset -a'

There is a bug in print_scan() function that may cause ksh to crash
while listing indexed arrays. The crash happens in nv_search() when
called from print_scan().

This applies a fix from Siteshwar Vashist:
https://www.mail-archive.com/ast-developers@lists.research.att.com/msg01944.html

src/cmd/ksh93/bltins/typeset.c:
- Call nv_scan() without the NV_IARRAY flag, even for a null scan.

src/cmd/ksh93/tests/arrays.sh:
- Add regression test for 'typeset -a' crash and check output.
This commit is contained in:
Martijn Dekker 2020-07-09 16:02:15 +01:00
parent a8f6d6b842
commit 5e7d335f2f
3 changed files with 12 additions and 1 deletions

2
NEWS
View file

@ -7,6 +7,8 @@ Any uppercase BUG_* names are modernish shell bug IDs.
- Fixed a crash on syntax error when sourcing/dotting multiple files.
- Fixed a crash when listing indexed arrays.
2020-07-07:
- Four of the date formats accepted by 'printf %()T' have had their

View file

@ -1497,7 +1497,7 @@ static void print_scan(Sfio_t *file, int flag, Dt_t *root, int option,struct tda
tp->scanmask |= (NV_DOUBLE|NV_EXPNOTE);
if(flag==NV_LTOU || flag==NV_UTOL)
tp->scanmask |= NV_UTOL|NV_LTOU;
namec = nv_scan(root,nullscan,(void*)tp,tp->scanmask,flag);
namec = nv_scan(root, nullscan, (void*)tp, tp->scanmask, flag&~NV_IARRAY);
argv = tp->argnam = (char**)stkalloc(tp->sh->stk,(namec+1)*sizeof(char*));
namec = nv_scan(root, pushname, (void*)tp, tp->scanmask, flag&~NV_IARRAY);
if(mbcoll())

View file

@ -666,4 +666,13 @@ typeset -A Foo
Foo=( [a]=AA;[b]=BB)
[[ ${Foo[a]} == AA ]] || err_exit 'Fooa[a] is {Foo[a]} not AA'
# ======
# Crash when listing an indexed array
expect=$'A=($\'\\\'\')\nB=(aa)\nC=(aa)'
actual=$("$SHELL" -c 'A[0]="'\''" B[0]=aa C[0]=aa; typeset -a') \
|| err_exit "Crash when listing indexed array (exit status $?)"
[[ $actual == "$expect" ]] || err_exit 'Incorrect output when listing indexed array' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
# ======
exit $((Errors<125?Errors:125))