Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdlib PR/43899: Nicolas Joly: setenv(3)/unsetenv(3...
details: https://anonhg.NetBSD.org/src/rev/9ab7b9b99c50
branches: trunk
changeset: 757795:9ab7b9b99c50
user: christos <christos%NetBSD.org@localhost>
date: Thu Sep 23 16:02:41 2010 +0000
description:
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.
diffstat:
lib/libc/stdlib/setenv.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diffs (27 lines):
diff -r f58833c0071a -r 9ab7b9b99c50 lib/libc/stdlib/setenv.c
--- a/lib/libc/stdlib/setenv.c Thu Sep 23 16:02:34 2010 +0000
+++ b/lib/libc/stdlib/setenv.c Thu Sep 23 16:02:41 2010 +0000
@@ -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));
Home |
Main Index |
Thread Index |
Old Index