From owner-svn-src-all@FreeBSD.ORG Sat Jan 1 13:26:18 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D05A5106564A; Sat, 1 Jan 2011 13:26:18 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7E6E58FC13; Sat, 1 Jan 2011 13:26:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p01DQIiL011765; Sat, 1 Jan 2011 13:26:18 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p01DQI8O011760; Sat, 1 Jan 2011 13:26:18 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201101011326.p01DQI8O011760@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 1 Jan 2011 13:26:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216870 - in head: bin/sh tools/regression/bin/sh/errors X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Jan 2011 13:26:19 -0000 Author: jilles Date: Sat Jan 1 13:26:18 2011 New Revision: 216870 URL: http://svn.freebsd.org/changeset/base/216870 Log: sh: Check readonly status for assignments on regular builtins. An error message is written, the builtin is not executed, nonzero exit status is returned but the shell does not abort. This was already checked for special builtins and external commands, with the same consequences except that the shell aborts for special builtins. Obtained from: NetBSD Added: head/tools/regression/bin/sh/errors/assignment-error2.0 (contents, props changed) Modified: head/bin/sh/eval.c head/bin/sh/var.c head/bin/sh/var.h Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Sat Jan 1 08:47:38 2011 (r216869) +++ head/bin/sh/eval.c Sat Jan 1 13:26:18 2011 (r216870) @@ -997,8 +997,7 @@ evalcommand(union node *cmd, int flags, */ if (argc == 0 && !(flags & EV_BACKCMD)) cmdentry.special = 1; - if (cmdentry.special) - listsetvar(cmdenviron); + listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET); if (argc > 0) bltinsetlocale(); commandname = argv[0]; Modified: head/bin/sh/var.c ============================================================================== --- head/bin/sh/var.c Sat Jan 1 08:47:38 2011 (r216869) +++ head/bin/sh/var.c Sat Jan 1 13:26:18 2011 (r216870) @@ -333,6 +333,8 @@ setvareq(char *s, int flags) len = strchr(s, '=') - s; error("%.*s: is read only", len, s); } + if (flags & VNOSET) + return; INTOFF; if (vp->func && (flags & VNOFUNC) == 0) @@ -365,6 +367,8 @@ setvareq(char *s, int flags) } } /* not found */ + if (flags & VNOSET) + return; vp = ckmalloc(sizeof (*vp)); vp->flags = flags; vp->text = s; @@ -386,13 +390,13 @@ setvareq(char *s, int flags) */ void -listsetvar(struct strlist *list) +listsetvar(struct strlist *list, int flags) { struct strlist *lp; INTOFF; for (lp = list ; lp ; lp = lp->next) { - setvareq(savestr(lp->text), 0); + setvareq(savestr(lp->text), flags); } INTON; } Modified: head/bin/sh/var.h ============================================================================== --- head/bin/sh/var.h Sat Jan 1 08:47:38 2011 (r216869) +++ head/bin/sh/var.h Sat Jan 1 13:26:18 2011 (r216870) @@ -45,6 +45,7 @@ #define VSTACK 0x10 /* text is allocated on the stack */ #define VUNSET 0x20 /* the variable is not set */ #define VNOFUNC 0x40 /* don't call the callback function */ +#define VNOSET 0x80 /* do not set variable - just readonly test */ struct var { @@ -106,7 +107,7 @@ void initvar(void); void setvar(const char *, const char *, int); void setvareq(char *, int); struct strlist; -void listsetvar(struct strlist *); +void listsetvar(struct strlist *, int); char *lookupvar(const char *); char *bltinlookup(const char *, int); void bltinsetlocale(void); Added: head/tools/regression/bin/sh/errors/assignment-error2.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/errors/assignment-error2.0 Sat Jan 1 13:26:18 2011 (r216870) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +set -e +HOME=/ +readonly HOME +cd /sbin +{ HOME=/bin cd; } 2>/dev/null || : +[ "$(pwd)" != /bin ]