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

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.
This commit is contained in:
Martijn Dekker 2022-06-22 17:02:25 +01:00
parent 4d50b69cbd
commit d8dc2a1d81
4 changed files with 19 additions and 1 deletions

5
NEWS
View file

@ -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

View file

@ -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. */

View file

@ -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);

View file

@ -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))