Module Name: src
Committed By: tron
Date: Mon Sep 9 10:21:28 UTC 2013
Modified Files:
src/lib/libc/stdlib: _env.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/_env.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/stdlib/_env.c
diff -u src/lib/libc/stdlib/_env.c:1.7 src/lib/libc/stdlib/_env.c:1.8
--- src/lib/libc/stdlib/_env.c:1.7 Mon Aug 19 22:14:37 2013
+++ src/lib/libc/stdlib/_env.c Mon Sep 9 10:21:28 2013
@@ -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_
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_
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 &&