aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/sh/parser.c5
-rw-r--r--tools/regression/bin/sh/execution/func3.07
2 files changed, 12 insertions, 0 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index ec1510bf4d5b..4c1b2726f789 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;
diff --git a/tools/regression/bin/sh/execution/func3.0 b/tools/regression/bin/sh/execution/func3.0
new file mode 100644
index 000000000000..f7a562a0baad
--- /dev/null
+++ b/tools/regression/bin/sh/execution/func3.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+# This may fail when parsing or when defining the function, or the definition
+# may silently do nothing. In no event may the function be executed.
+
+sh -c 'unset() { echo overriding function executed, bad; }; v=1; unset v; exit "${v-0}"' 2>/dev/null
+: