Date: Sun, 24 Oct 2010 22:03:21 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r214304 - in head: bin/sh tools/regression/bin/sh/execution Message-ID: <201010242203.o9OM3LLd041679@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Sun Oct 24 22:03:21 2010 New Revision: 214304 URL: http://svn.freebsd.org/changeset/base/214304 Log: 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) Added: head/tools/regression/bin/sh/execution/func3.0 (contents, props changed) Modified: head/bin/sh/parser.c Modified: head/bin/sh/parser.c ============================================================================== --- head/bin/sh/parser.c Sun Oct 24 22:02:36 2010 (r214303) +++ head/bin/sh/parser.c Sun Oct 24 22:03:21 2010 (r214304) @@ -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 * 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 * 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; Added: head/tools/regression/bin/sh/execution/func3.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/execution/func3.0 Sun Oct 24 22:03:21 2010 (r214304) @@ -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 +:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010242203.o9OM3LLd041679>