diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 80761dd47..fe7d036c4 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -732,7 +732,8 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp np = nv_open(name,troot,nvflags|((nvflags&NV_ASSIGN)?0:NV_ARRAY)|((iarray|(nvflags&(NV_REF|NV_NOADD)==NV_REF))?NV_FARRAY:0)); if(!np) continue; - if(np->nvflag&NV_RDONLY && !tp->pflag && (flag & ~NV_NOFREE) != NV_RDONLY) + if(np->nvflag&NV_RDONLY && !tp->pflag + && (flag & ~(NV_ASSIGN|NV_RDONLY|NV_EXPORT))) /* allow readonly/export on readonly vars */ { errormsg(SH_DICT,ERROR_exit(1),e_readonly,nv_name(np)); UNREACHABLE(); diff --git a/src/cmd/ksh93/tests/readonly.sh b/src/cmd/ksh93/tests/readonly.sh old mode 100644 new mode 100755 index cb8c29b11..778c54090 --- a/src/cmd/ksh93/tests/readonly.sh +++ b/src/cmd/ksh93/tests/readonly.sh @@ -331,5 +331,14 @@ do done unset i n got rtests +# ====== +# readonly variables should still accept setting the readonly or export attributes +# https://github.com/ksh93/ksh/issues/258 +(readonly v=1; readonly v) 2>/dev/null || err_exit "readonly variable cannot be set readonly (1)" +(readonly v=1; typeset -r v) 2>/dev/null || err_exit "readonly variable cannot be set readonly (2)" +(readonly v=1; export v) 2>/dev/null || err_exit "readonly variable cannot be exported (1)" +(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" + # ====== exit $((Errors<125?Errors:125))