diff --git a/NEWS b/NEWS index 62e5df85b..6c1a2db32 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ Any uppercase BUG_* names are modernish shell bug IDs. 2020-06-11: +- Fixed a bug that caused running 'builtin -d' on a special builtin to + delete it. The man page for the 'builtin' command documents that special + builtins cannot be deleted. + - POSIX compliance fix: It is now possible to set shell functions named 'alias' or 'unalias', overriding the commands by the same names. In technical terms, they are now regular builtins, not special builtins. diff --git a/src/cmd/ksh93/sh/nvdisc.c b/src/cmd/ksh93/sh/nvdisc.c index b8a741a9c..db027fad8 100644 --- a/src/cmd/ksh93/sh/nvdisc.c +++ b/src/cmd/ksh93/sh/nvdisc.c @@ -1203,6 +1203,8 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra) stakseek(offset); if(extra == (void*)1) { + if(nv_isattr(np,BLT_SPC)) + errormsg(SH_DICT,ERROR_exit(1),"cannot delete: %s%s",name,is_spcbuiltin); if(np->nvfun && !nv_isattr(np,NV_NOFREE)) free((void*)np->nvfun); dtdelete(sh.bltin_tree,np); diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 0fd7a2810..e270a11d1 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -686,5 +686,11 @@ PATH=$tmp:$PATH $SHELL <<-\EOF || err_exit "'whence' gets wrong path on init" [[ -x $wc ]] EOF +# ====== +# `builtin -d` should not delete special builtins +(builtin -d export 2> /dev/null +PATH=/dev/null +whence -q export) || err_exit '`builtin -d` deletes special builtins' + # ====== exit $((Errors<125?Errors:125))