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:
parent
be79f6c038
commit
1ad2891b6d
|
@ -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.
|
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#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 */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#include "namespace.h"
|
#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;
|
size_t new_size, num_entries, required_size;
|
||||||
char **new_environ;
|
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. */
|
/* Search for an existing environment variable of the given name. */
|
||||||
num_entries = 0;
|
num_entries = 0;
|
||||||
while (environ[num_entries] != NULL) {
|
while (environ[num_entries] != NULL) {
|
||||||
|
@ -275,6 +271,10 @@ __getenvslot(const char *name, size_t l_name, bool allocate)
|
||||||
if (!allocate)
|
if (!allocate)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* Does the environ need scrubbing? */
|
||||||
|
if (environ != allocated_environ && allocated_environ != NULL)
|
||||||
|
__scrubenv();
|
||||||
|
|
||||||
/* Create a new slot in the environment. */
|
/* Create a new slot in the environment. */
|
||||||
required_size = num_entries + 1;
|
required_size = num_entries + 1;
|
||||||
if (environ == allocated_environ &&
|
if (environ == allocated_environ &&
|
||||||
|
|
Loading…
Reference in New Issue