diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index ae3f582d8..e4dec7d5a 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -261,6 +261,7 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ) Shell_t *shp = sh_getinterp(); register char *cp; register Namval_t *np, *mp; + char *eqp; char *trap=shp->st.trap[SH_DEBUGTRAP]; char *prefix = shp->prefix; int traceon = (sh_isoption(SH_XTRACE)!=0); @@ -592,6 +593,19 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ) cp = arg->argval; mp = 0; } + if(eqp = strchr(cp,'=')) + { + /* Check for read-only */ + *eqp = '\0'; + np = nv_search(cp,shp->var_tree,0); + *eqp = '='; + if(np && nv_isattr(np,NV_RDONLY)) + { + errormsg(SH_DICT,ERROR_exit(1),e_readonly,nv_name(np)); + UNREACHABLE(); + } + + } np = nv_open(cp,shp->prefix_root?shp->prefix_root:shp->var_tree,flags); if(!np->nvfun && (flags&NV_NOREF)) { diff --git a/src/cmd/ksh93/tests/readonly.sh b/src/cmd/ksh93/tests/readonly.sh index 778c54090..64b35f5e2 100755 --- a/src/cmd/ksh93/tests/readonly.sh +++ b/src/cmd/ksh93/tests/readonly.sh @@ -319,6 +319,7 @@ n=${#rtests[@]} for ((i=0; i<$n; i++)) do got=$( + ((.sh.version < 20210404)) && ulimit -t unlimited 2>/dev/null # fork to dodge an arith recursion detection bug trap "${rtests[$i].res}" EXIT eval "${rtests[$i].ini}" eval "${rtests[$i].chg}" 2>&1 @@ -340,5 +341,9 @@ unset i n got rtests (readonly v=1; typeset -x v) 2>/dev/null || err_exit "readonly variable cannot be exported (2)" (readonly v=1; typeset -rx v) 2>/dev/null || err_exit "readonly variable cannot be set readonly and exported" +# ====== +# the environment list was not checked for readonly for commands that are not fork()ed +(readonly v=1; v=2 true) 2>/dev/null && err_exit 'readonly not verified for command environment list' + # ====== exit $((Errors<125?Errors:125))