Subject: Re: lib/12393: segfault in setenv(3)
To: None <cgd@sibyte.com>
From: Simon J. Gerraty <sjg@quick.com.au>
List: netbsd-bugs
Date: 03/12/2001 11:33:05
So, this would be a better fix?
Index: lib/libc/stdlib/setenv.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/stdlib/setenv.c,v
retrieving revision 1.19
diff -u -p -r1.19 setenv.c
--- lib/libc/stdlib/setenv.c 2000/12/20 18:38:30 1.19
+++ lib/libc/stdlib/setenv.c 2001/03/12 19:31:55
@@ -102,12 +102,13 @@ setenv(name, value, rewrite)
for (p = environ, cnt = 0; *p; ++p, ++cnt);
if (alloced) { /* just increase size */
- environ = realloc(environ,
- (size_t)(sizeof(char *) * (cnt + 2)));
- if (!environ) {
+ p = realloc(environ,
+ (size_t)(sizeof(char *) * (cnt + 2)));
+ if (!p) {
rwlock_unlock(&__environ_lock);
return (-1);
}
+ environ = p;
}
else { /* get new space */
alloced = 1; /* copy old entries into it */