diff options
author | jilles <jilles@FreeBSD.org> | 2010-10-24 22:03:21 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-10-24 22:03:21 +0000 |
commit | 58038d3e9e1f45ea4dccdfeb21e3f9bb40ae4950 (patch) | |
tree | c67a589303115497405ea6d6c7c7ed067acf7e9f /bin | |
parent | 520543ca439ef2838b69c6bf1e321ba7ce98debf (diff) | |
download | FreeBSD-src-58038d3e9e1f45ea4dccdfeb21e3f9bb40ae4950.zip FreeBSD-src-58038d3e9e1f45ea4dccdfeb21e3f9bb40ae4950.tar.gz |
sh: Do not allow overriding a special builtin with a function.
This is a syntax error.
POSIX does not say explicitly whether defining a function with the same name
as a special builtin is allowed, but it does say that it is impossible to
call such a function.
A special builtin can still be overridden with an alias.
This commit is part of a set of changes that will ensure that when
something looks like a special builtin to the parser, it is one. (Not the
other way around, as it remains possible to call a special builtin named
by a variable or other substitution.)
Exp-run done by: pav (with some other sh(1) changes)
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/parser.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index ec1510b..4c1b272 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$"); #include "alias.h" #include "show.h" #include "eval.h" +#include "exec.h" /* to check for special builtins */ #ifndef NO_HISTORY #include "myhistedit.h" #endif @@ -606,6 +607,7 @@ simplecmd(union node **rpp, union node *redir) union node *args, **app; union node **orig_rpp = rpp; union node *n = NULL; + int special; /* If we don't have any redirections already, then we must reset */ /* rpp to be the address of the local redir variable. */ @@ -647,6 +649,9 @@ simplecmd(union node **rpp, union node *redir) strchr(n->narg.text, '/')) synerror("Bad function name"); rmescapes(n->narg.text); + if (find_builtin(n->narg.text, &special) >= 0 && + special) + synerror("Cannot override a special builtin with a function"); n->type = NDEFUN; n->narg.next = command(); funclinno = 0; |