Module Name:    src
Committed By:   christos
Date:           Thu Sep 23 16:02:41 UTC 2010

Modified Files:
        src/lib/libc/stdlib: setenv.c

Log Message:
PR/43899: Nicolas Joly: setenv(3)/unsetenv(3) memory leak.
Partial fix: Don't allocate a new string if the length is equal to the
old length, because presumably the old string was also nul terminated
so it has the extra byte needed.
The real fix is to keep an adjunct array of bits, one for each environment
variable and keep track if the entry was allocated or not so that we can
free it in unsetenv.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdlib/setenv.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/setenv.c
diff -u src/lib/libc/stdlib/setenv.c:1.32 src/lib/libc/stdlib/setenv.c:1.33
--- src/lib/libc/stdlib/setenv.c:1.32	Wed Dec  2 04:34:51 2009
+++ src/lib/libc/stdlib/setenv.c	Thu Sep 23 12:02:41 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: setenv.c,v 1.32 2009/12/02 09:34:51 enami Exp $	*/
+/*	$NetBSD: setenv.c,v 1.33 2010/09/23 16:02:41 christos Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)setenv.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: setenv.c,v 1.32 2009/12/02 09:34:51 enami Exp $");
+__RCSID("$NetBSD: setenv.c,v 1.33 2010/09/23 16:02:41 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -82,7 +82,7 @@
 	if ((c = __findenv(name, &offset)) != NULL) {
 		if (!rewrite)
 			goto good;
-		if (strlen(c) >= l_value)	/* old larger; copy over */
+		if (strlen(c) > l_value)	/* old larger; copy over */
 			goto copy;
 	} else {					/* create new slot */
 		size = (size_t)(sizeof(char *) * (offset + 2));

Reply via email to