From owner-svn-src-head@FreeBSD.ORG Fri Jun 10 22:42:01 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 16CA81065670; Fri, 10 Jun 2011 22:42:01 +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 F0C108FC14; Fri, 10 Jun 2011 22:42:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p5AMg0Sx046343; Fri, 10 Jun 2011 22:42:00 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p5AMg0PN046338; Fri, 10 Jun 2011 22:42:00 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201106102242.p5AMg0PN046338@svn.freebsd.org> From: Jilles Tjoelker Date: Fri, 10 Jun 2011 22:42:00 +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: r222957 - in head: bin/sh tools/regression/bin/sh/parameters X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jun 2011 22:42:01 -0000 Author: jilles Date: Fri Jun 10 22:42:00 2011 New Revision: 222957 URL: http://svn.freebsd.org/changeset/base/222957 Log: sh: Do parameter expansion on ENV before using it. This is required by POSIX, and allows things like ENV=\$HOME/.shrc. Note that tilde expansion is explicitly not performed. Added: head/tools/regression/bin/sh/parameters/env1.0 (contents, props changed) Modified: head/bin/sh/main.c head/bin/sh/sh.1 Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Fri Jun 10 22:38:31 2011 (r222956) +++ head/bin/sh/main.c Fri Jun 10 22:42:00 2011 (r222957) @@ -78,7 +78,7 @@ int rootshell; struct jmploc main_handler; int localeisutf8, initial_localeisutf8; -static void read_profile(const char *); +static void read_profile(char *); static char *find_dot_file(char *); /* @@ -92,7 +92,7 @@ static char *find_dot_file(char *); int main(int argc, char *argv[]) { - struct stackmark smark; + struct stackmark smark, smark2; volatile int state; char *shinit; @@ -139,6 +139,7 @@ main(int argc, char *argv[]) rootshell = 1; init(); setstackmark(&smark); + setstackmark(&smark2); procargs(argc, argv); pwd_init(iflag); if (iflag) @@ -163,6 +164,7 @@ state2: } state3: state = 4; + popstackmark(&smark2); if (minusc) { evalstring(minusc, sflag ? 0 : EV_EXIT); } @@ -235,12 +237,16 @@ cmdloop(int top) */ static void -read_profile(const char *name) +read_profile(char *name) { int fd; + const char *expandedname; + expandedname = expandstr(name); + if (expandedname == NULL) + return; INTOFF; - if ((fd = open(name, O_RDONLY)) >= 0) + if ((fd = open(expandedname, O_RDONLY)) >= 0) setinputfd(fd, 1); INTON; if (fd < 0) Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Fri Jun 10 22:38:31 2011 (r222956) +++ head/bin/sh/sh.1 Fri Jun 10 22:42:00 2011 (r222957) @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd June 9, 2011 +.Dd June 10, 2011 .Dt SH 1 .Os .Sh NAME @@ -124,8 +124,8 @@ If the environment variable .Ev ENV is set on entry to a shell, or is set in the .Pa .profile -of a login shell, the shell then reads commands from the file named in -.Ev ENV . +of a login shell, the shell then subjects its value to parameter expansion +and arithmetic expansion and reads commands from the named file. Therefore, a user should place commands that are to be executed only at login time in the .Pa .profile Added: head/tools/regression/bin/sh/parameters/env1.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/parameters/env1.0 Fri Jun 10 22:42:00 2011 (r222957) @@ -0,0 +1,11 @@ +# $FreeBSD$ + +export key='must contain this' +unset x +r=$(ENV="\${x?\$key}" ${SH} -i +m 2>&1 >/dev/null <<\EOF +exit 0 +EOF +) && case $r in +*"$key"*) true ;; +*) false ;; +esac