From owner-svn-src-head@FreeBSD.ORG Tue Dec 1 06:42:48 2009 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 964A7106568F; Tue, 1 Dec 2009 06:42:48 +0000 (UTC) (envelope-from green@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 85F028FC17; Tue, 1 Dec 2009 06:42:48 +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 nB16gmtn055296; Tue, 1 Dec 2009 06:42:48 GMT (envelope-from green@svn.freebsd.org) Received: (from green@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nB16glnH055295; Tue, 1 Dec 2009 06:42:47 GMT (envelope-from green@svn.freebsd.org) Message-Id: <200912010642.nB16glnH055295@svn.freebsd.org> From: Brian Feldman Date: Tue, 1 Dec 2009 06:42:47 +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: r199987 - head/lib/libc/stdlib 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: Tue, 01 Dec 2009 06:42:48 -0000 Author: green Date: Tue Dec 1 06:42:47 2009 New Revision: 199987 URL: http://svn.freebsd.org/changeset/base/199987 Log: Temporarily revert the previous change because the linker has been modified so that it will abort when the environment is bad. Modified: head/lib/libc/stdlib/getenv.c Modified: head/lib/libc/stdlib/getenv.c ============================================================================== --- head/lib/libc/stdlib/getenv.c Tue Dec 1 06:15:19 2009 (r199986) +++ head/lib/libc/stdlib/getenv.c Tue Dec 1 06:42:47 2009 (r199987) @@ -96,8 +96,6 @@ static int envVarsTotal = 0; /* Deinitialization of new environment. */ static void __attribute__ ((destructor)) __clean_env_destructor(void); -/* Resetting the environ pointer will affect the env functions. */ -static int __merge_environ(void); /* @@ -192,9 +190,6 @@ __findenv_environ(const char *name, size { int envNdx; - if (environ == NULL) - return (NULL); - /* Find variable within environ. */ for (envNdx = 0; environ[envNdx] != NULL; envNdx++) if (strncmpeq(environ[envNdx], name, nameLen)) @@ -333,7 +328,6 @@ __build_env(void) { char **env; int activeNdx; - int checking; int envNdx; int savedErrno; size_t nameLen; @@ -345,23 +339,6 @@ __build_env(void) /* Count environment variables. */ for (env = environ, envVarsTotal = 0; *env != NULL; env++) envVarsTotal++; - /* Remove any corrupt variable entries, but do not error out. */ - checking = 0; - while (checking < envVarsTotal) { - if (strchr(environ[checking], '=') != NULL) { - checking++; - } else { - __env_warnx(CorruptEnvValueMsg, - environ[checking], strlen(environ[checking])); - /* - * Pull back all remaining entries from checking + 1 - * through envVarsTotal, including the NULL at the end. - */ - memmove(&environ[checking], &environ[checking + 1], - sizeof(char *) * (envVarsTotal - checking)); - envVarsTotal--; - } - } envVarsSize = envVarsTotal * 2; /* Create new environment. */ @@ -376,8 +353,18 @@ __build_env(void) strdup(environ[envVarsTotal - envNdx - 1]); if (envVars[envNdx].name == NULL) goto Failure; - envVars[envNdx].value = strchr(envVars[envNdx].name, '=') + 1; - envVars[envNdx].valueSize = strlen(envVars[envNdx].value); + envVars[envNdx].value = strchr(envVars[envNdx].name, '='); + if (envVars[envNdx].value != NULL) { + envVars[envNdx].value++; + envVars[envNdx].valueSize = + strlen(envVars[envNdx].value); + } else { + __env_warnx(CorruptEnvValueMsg, envVars[envNdx].name, + strlen(envVars[envNdx].name)); + errno = EFAULT; + goto Failure; + } + /* * Find most current version of variable to make active. This * will prevent multiple active variables from being created @@ -439,18 +426,22 @@ getenv(const char *name) } /* - * If we have not already allocated memory by performing - * write operations on the environment, avoid doing so now. + * An empty environment (environ or its first value) regardless if + * environ has been copied before will return a NULL. + * + * If the environment is not empty, find an environment variable via + * environ if environ has not been copied via an *env() call or been + * replaced by a running program, otherwise, use the rebuilt + * environment. */ - if (envVars == NULL) - return (__findenv_environ(name, nameLen)); - - /* Synchronize environment. */ - if (__merge_environ() == -1) + if (environ == NULL || environ[0] == NULL) return (NULL); - - envNdx = envVarsTotal - 1; - return (__findenv(name, nameLen, &envNdx, true)); + else if (envVars == NULL || environ != intEnviron) + return (__findenv_environ(name, nameLen)); + else { + envNdx = envVarsTotal - 1; + return (__findenv(name, nameLen, &envNdx, true)); + } } @@ -568,7 +559,8 @@ __merge_environ(void) if ((equals = strchr(*env, '=')) == NULL) { __env_warnx(CorruptEnvValueMsg, *env, strlen(*env)); - continue; + errno = EFAULT; + return (-1); } if (__setenv(*env, equals - *env, equals + 1, 1) == -1)