From d8dc2a1d814a7fdc69215be382602435cdb7ae6a Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 22 Jun 2022 17:02:25 +0100 Subject: [PATCH] sh_setenviron(): deactivate compound assignment prefix Reproducers: $ ksh -c 'typeset -a arr=( ( (a $(($(echo 1) + 1)) c)1))' ksh: echo: arr[0]._AST_FEATURES=CONFORMANCE - ast UNIVERSE - ucb: cannot be an array ksh: [1]=1: invalid variable name $ ksh -c 'typeset -a arr=( (a $(($(echo 1) + 1)) c)1)' ksh: echo: arr._AST_FEATURES=CONFORMANCE - ast UNIVERSE - ucb: is not an identifier ksh: [1]=1: invalid variable name src/cmd/ksh93/sh/name.c: sh_setenviron(): - Save and clear the current compound assignment prefix (sh.prefix) while assigning to the _AST_FEATURES variable. --- NEWS | 5 +++++ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh/name.c | 4 ++++ src/cmd/ksh93/tests/comvar.sh | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index b21cc6b59..30bf4199f 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0 Any uppercase BUG_* names are modernish shell bug IDs. +2022-06-22: + +- Fixed: 'echo' failed when used inside a command substitution that + is inside a nested compound assignment. + 2022-06-20: - Fixed a race condition that could cause redirections to fail with a diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 84543317b..8f918ada4 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -23,7 +23,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2022-06-20" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2022-06-22" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index f6aa65b1c..9053365d0 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -3125,7 +3125,11 @@ char* sh_setenviron(const char *name) register Namval_t *np; if(name) { + char *save_prefix = sh.prefix; + /* deactivate a possible compound assignment */ + sh.prefix = NIL(char*); np = nv_open(name,sh.var_tree,NV_EXPORT|NV_IDENT|NV_NOARRAY|NV_ASSIGN); + sh.prefix = save_prefix; if(strchr(name,'=')) return(nv_getval(np)); _nv_unset(np,0); diff --git a/src/cmd/ksh93/tests/comvar.sh b/src/cmd/ksh93/tests/comvar.sh index a6a4b20c7..11118aa47 100755 --- a/src/cmd/ksh93/tests/comvar.sh +++ b/src/cmd/ksh93/tests/comvar.sh @@ -706,5 +706,14 @@ EOF "$SHELL" -c "$compound_array" ) || err_exit 'unsetting an array turned into a compound variable fails' +# ====== +# before 2022-06-22, this resulted in: +# ksh: echo: arr[0]._AST_FEATURES=CONFORMANCE - ast UNIVERSE - ucb: cannot be an array +# ksh: [1]=1: invalid variable name +got=$(set +x; eval 'typeset -a arr=( ( (a $(($(echo 1) + 1)) c)1))' 2>&1; typeset -p arr) +exp='typeset -a arr=(((a 2 c) 1) )' +[[ $got == "$exp" ]] || err_exit "'echo' environment messed up by compound assignment" \ + "(expected $(printf %q "$exp"), got $(printf %q "$got"))" + # ====== exit $((Errors<125?Errors:125))