From 24241ad7410890baa4999bca4095699607923178 Mon Sep 17 00:00:00 2001 From: millert <> Date: Mon, 2 Feb 1998 22:44:53 +0000 Subject: [PATCH] Don't override environ if realloc() fails. Pointed out by Dave Bodenstab --- src/lib/libc/stdlib/setenv.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c index 8838eb87..b6f261e6 100644 --- a/src/lib/libc/stdlib/setenv.c +++ b/src/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 @@ -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 */