diff --git a/NEWS b/NEWS index d6b2ce4b5..9ab2d5780 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index d84bdf49b..a46617726 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -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()) diff --git a/src/cmd/ksh93/tests/arrays.sh b/src/cmd/ksh93/tests/arrays.sh index a766bd37f..59e01d9de 100755 --- a/src/cmd/ksh93/tests/arrays.sh +++ b/src/cmd/ksh93/tests/arrays.sh @@ -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))