Module Name:    src
Committed By:   tron
Date:           Sat Oct  2 10:51:07 UTC 2010

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

Log Message:
Make sure that all extra elements of the environment vector are set
to NULL. This stop su(1) from crashing.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/stdlib/getenv.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/getenv.c
diff -u src/lib/libc/stdlib/getenv.c:1.24 src/lib/libc/stdlib/getenv.c:1.25
--- src/lib/libc/stdlib/getenv.c:1.24	Fri Oct  1 20:11:32 2010
+++ src/lib/libc/stdlib/getenv.c	Sat Oct  2 10:51:07 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: getenv.c,v 1.24 2010/10/01 20:11:32 christos Exp $	*/
+/*	$NetBSD: getenv.c,v 1.25 2010/10/02 10:51:07 tron Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getenv.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getenv.c,v 1.24 2010/10/01 20:11:32 christos Exp $");
+__RCSID("$NetBSD: getenv.c,v 1.25 2010/10/02 10:51:07 tron Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -120,15 +120,18 @@
 	if (saveenv == environ) {		/* just increase size */
 		if ((p = realloc(saveenv, nl * sizeof(*p))) == NULL)
 			return -1;
+		(void)memset(&p[environ_malloced_len], 0,
+		    (nl - environ_malloced_len) * sizeof(*p));
 		saveenv = p;
 	} else {				/* get new space */
 		free(saveenv);
 		if ((saveenv = malloc(nl * sizeof(*saveenv))) == NULL)
 			return -1;
 		(void)memcpy(saveenv, environ, (nl - 2) * sizeof(*saveenv));
+		saveenv[nl - 2] = NULL;
+		saveenv[nl - 1] = NULL;
 	}
 	environ = saveenv;
-	environ[offset + 1] = NULL;
 
 	p = realloc(__environ_malloced, nl * sizeof(*p));
 	if (p == NULL)

Reply via email to