Skip to content

Commit 74b4162

Browse files
JohnoKingMcDutchie
authored andcommitted
Fix set +r so that it cannot unset the restricted option
The ksh man page documents that the restricted option cannot be unset once it is set, which means `set +r` should be invalid. While this was true for `set +o restricted`, `set +r` was causing the restricted option to be unset. The fix for this problem comes from one of Solaris' patches, which adds an error check to prevent this behavior. Solaris' patch: https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/020-CR6919590.patch src/cmd/ksh93/sh/args.c: - Add an error check to stop `set +r` from unsetting the restricted option. src/cmd/ksh93/tests/restricted.sh: - Add two regression tests to make sure the restricted option cannot be unset. (cherry picked from commit bef4fee404d8e24b38fce66420c14a39ac4a123e)
1 parent 9cef2d5 commit 74b4162

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/cmd/ksh93/sh/args.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ int sh_argopts(int argc,register char *argv[], void *context)
302302
}
303303
else
304304
{
305+
if ((o == SH_RESTRICTED) && sh_isoption(SH_RESTRICTED))
306+
errormsg(SH_DICT,ERROR_exit(1),e_restricted,"r"); /* set -r cannot be unset */
305307
if(o==SH_XTRACE)
306308
trace = 0;
307309
off_option(&newflags,o);

src/cmd/ksh93/tests/restricted.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,10 @@ for i in PATH ENV FPATH
8787
do check_restricted "function foo { typeset $i=foobar;};foo" || err_exit "$i can be changed in function by using typeset"
8888
done
8989

90+
# ======
91+
# `set +r` and `set +o restricted` should not unset the restricted option
92+
check_restricted 'set +r' 2> /dev/null || err_exit '`set +r` unsets the restricted option'
93+
check_restricted 'set +o restricted' 2> /dev/null || err_exit '`set +o restricted` unsets the restricted option'
94+
95+
# ======
9096
exit $((Errors<125?Errors:125))

0 commit comments

Comments
 (0)