Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Jun 2011 22:42:00 +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: r222957 - in head: bin/sh tools/regression/bin/sh/parameters
Message-ID:  <201106102242.p5AMg0PN046338@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106102242.p5AMg0PN046338>