Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib Don't scrub the environment unless we are go...



details:   https://anonhg.NetBSD.org/src/rev/50dd003a9777
branches:  trunk
changeset: 789825:50dd003a9777
user:      tron <tron%NetBSD.org@localhost>
date:      Mon Sep 09 10:21:28 2013 +0000

description:
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.

diffstat:

 lib/libc/stdlib/_env.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (40 lines):

diff -r 21965c2f475e -r 50dd003a9777 lib/libc/stdlib/_env.c
--- a/lib/libc/stdlib/_env.c    Mon Sep 09 09:02:25 2013 +0000
+++ b/lib/libc/stdlib/_env.c    Mon Sep 09 10:21:28 2013 +0000
@@ -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 @@
        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 @@
        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 &&



Home | Main Index | Thread Index | Old Index