diff options
author | millert <> | 1998-02-02 22:44:53 +0000 |
---|---|---|
committer | millert <> | 1998-02-02 22:44:53 +0000 |
commit | 41b1d7242a8ea86e10caae6482d05b00f5900341 (patch) | |
tree | 414188c8f6098e3925b6dc6024f0ae5d3526792c | |
parent | b08d7479e8ef6db58c3e1b0818e010519bac57ba (diff) | |
download | openbsd-41b1d7242a8ea86e10caae6482d05b00f5900341.tar.gz openbsd-41b1d7242a8ea86e10caae6482d05b00f5900341.tar.bz2 openbsd-41b1d7242a8ea86e10caae6482d05b00f5900341.zip |
Don't override environ if realloc() fails. Pointed out by
Dave Bodenstab <imdave@mcs.net>
-rw-r--r-- | src/lib/libc/stdlib/setenv.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c index 8838eb8780..b6f261e61c 100644 --- a/src/lib/libc/stdlib/setenv.c +++ b/src/lib/libc/stdlib/setenv.c | |||
@@ -32,7 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char *rcsid = "$OpenBSD: setenv.c,v 1.2 1996/08/19 08:33:48 tholo Exp $"; | 35 | static char *rcsid = "$OpenBSD: setenv.c,v 1.3 1998/02/02 22:44:53 millert Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
@@ -71,10 +71,11 @@ setenv(name, value, rewrite) | |||
71 | 71 | ||
72 | for (P = environ, cnt = 0; *P; ++P, ++cnt); | 72 | for (P = environ, cnt = 0; *P; ++P, ++cnt); |
73 | if (alloced) { /* just increase size */ | 73 | if (alloced) { /* just increase size */ |
74 | environ = (char **)realloc((char *)environ, | 74 | P = (char **)realloc((void *)environ, |
75 | (size_t)(sizeof(char *) * (cnt + 2))); | 75 | (size_t)(sizeof(char *) * (cnt + 2))); |
76 | if (!environ) | 76 | if (!P) |
77 | return (-1); | 77 | return (-1); |
78 | environ = P; | ||
78 | } | 79 | } |
79 | else { /* get new space */ | 80 | else { /* get new space */ |
80 | alloced = 1; /* copy old entries into it */ | 81 | alloced = 1; /* copy old entries into it */ |