aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2000-01-27 16:12:03 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2000-01-27 16:12:03 +0000
commit7e205084773565f92c7780abc20916219df2ce46 (patch)
treea344fd26bff1f6f0bb65b34715a92f8090e5bd0b
parentf669e3af26f7fe13d4546b35c5682a641d60e7bf (diff)
downloadsrc-7e205084773565f92c7780abc20916219df2ce46.tar.gz
src-7e205084773565f92c7780abc20916219df2ce46.zip
o Back out rev 1.4 - reallocf() failure clobbers existing `environ'.
o Do not override `environ' if realloc() fails, leave it intact. o Set `alloced' only when memory is actually allocated. PR: bin/5604 (2nd part) Reviewed by: bde
Notes
Notes: svn path=/head/; revision=56676
-rw-r--r--lib/libc/stdlib/setenv.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c
index 4c00b6e882f3..96f22a3e6ce5 100644
--- a/lib/libc/stdlib/setenv.c
+++ b/lib/libc/stdlib/setenv.c
@@ -32,7 +32,10 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)setenv.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] = "$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
#include <stddef.h>
@@ -73,16 +76,18 @@ setenv(name, value, rewrite)
for (p = environ, cnt = 0; *p; ++p, ++cnt);
if (alloced) { /* just increase size */
- environ = (char **)reallocf((char *)environ,
+ p = (char **)realloc((char *)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 */
+ /* copy old entries into it */
p = malloc((size_t)(sizeof(char *) * (cnt + 2)));
if (!p)
return (-1);
+ alloced = 1;
bcopy(environ, p, cnt * sizeof(char *));
environ = p;
}