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

builtin -d should not delete special builtins

The man page for the builtin command says special builtins cannot
be deleted. This wasn't the case though, running `builtin -d` on
a special builtin was deleting it. As an example, the following
set of commands was ending with 'export: not found':

$ builtin -d export
$ export foo=bar

This commit backports the bugfix from ksh93v- (2014-12-24-beta),
which added an error check to prevent special builtins from being
deleted.

src/cmd/ksh93/sh/nvdisc.c:
 - Add an error check to prevent special builtins from being deleted.

src/cmd/ksh93/tests/builtins.sh
 - Add a regression test for using `builtin -d` on special builtins.
This commit is contained in:
Johnothan King 2020-06-11 20:18:01 -07:00
parent 7b82c338da
commit 017d088c39
3 changed files with 12 additions and 0 deletions

View file

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