Don't scrub the environment unless we are going to change it. This should

prevent crashes in applications which carefully and manually construct
a temporary environment and later restore the original environment
like Emacs 24.

Problem reported by Thomas Klausner on "pkgsrc-users" mailing list.
This commit is contained in:
tron 2013-09-09 10:21:28 +00:00
parent be79f6c038
commit 1ad2891b6d
1 changed files with 6 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: _env.c,v 1.7 2013/08/19 22:14:37 matt Exp $ */
/* $NetBSD: _env.c,v 1.8 2013/09/09 10:21:28 tron Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _env.c,v 1.7 2013/08/19 22:14:37 matt Exp $");
__RCSID("$NetBSD: _env.c,v 1.8 2013/09/09 10:21:28 tron Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -256,10 +256,6 @@ __getenvslot(const char *name, size_t l_name, bool allocate)
size_t new_size, num_entries, required_size;
char **new_environ;
/* Does the environ need scrubbing? */
if (environ != allocated_environ && allocated_environ != NULL)
__scrubenv();
/* Search for an existing environment variable of the given name. */
num_entries = 0;
while (environ[num_entries] != NULL) {
@ -275,6 +271,10 @@ __getenvslot(const char *name, size_t l_name, bool allocate)
if (!allocate)
return -1;
/* Does the environ need scrubbing? */
if (environ != allocated_environ && allocated_environ != NULL)
__scrubenv();
/* Create a new slot in the environment. */
required_size = num_entries + 1;
if (environ == allocated_environ &&