summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/setenv.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1998-02-02 22:44:53 +0000
committermillert <millert@openbsd.org>1998-02-02 22:44:53 +0000
commit48d1b8ab4f15c2999c8d3cbee4bc957299486e7b (patch)
treee95aabf49aa6be0c5a47748045caafcd48a3c168 /lib/libc/stdlib/setenv.c
parentsupport non-ISA case (diff)
downloadwireguard-openbsd-48d1b8ab4f15c2999c8d3cbee4bc957299486e7b.tar.xz
wireguard-openbsd-48d1b8ab4f15c2999c8d3cbee4bc957299486e7b.zip
Don't override environ if realloc() fails. Pointed out by
Dave Bodenstab <imdave@mcs.net>
Diffstat (limited to 'lib/libc/stdlib/setenv.c')
-rw-r--r--lib/libc/stdlib/setenv.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c
index 8838eb87809..b6f261e61cf 100644
--- a/lib/libc/stdlib/setenv.c
+++ b/lib/libc/stdlib/setenv.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: setenv.c,v 1.2 1996/08/19 08:33:48 tholo Exp $";
+static char *rcsid = "$OpenBSD: setenv.c,v 1.3 1998/02/02 22:44:53 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
@@ -71,10 +71,11 @@ setenv(name, value, rewrite)
for (P = environ, cnt = 0; *P; ++P, ++cnt);
if (alloced) { /* just increase size */
- environ = (char **)realloc((char *)environ,
+ P = (char **)realloc((void *)environ,
(size_t)(sizeof(char *) * (cnt + 2)));
- if (!environ)
+ if (!P)
return (-1);
+ environ = P;
}
else { /* get new space */
alloced = 1; /* copy old entries into it */