summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/setenv.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2014-10-08 05:33:31 +0000
committerderaadt <deraadt@openbsd.org>2014-10-08 05:33:31 +0000
commited7f1a0205517ee12355db7b347b478c611e3fad (patch)
tree77d66ad1f10cdb9af6b6566b5b59135ba71d79e1 /lib/libc/stdlib/setenv.c
parentobvious conversion of realloc() to reallocarray(). Luckily this is (diff)
downloadwireguard-openbsd-ed7f1a0205517ee12355db7b347b478c611e3fad.tar.xz
wireguard-openbsd-ed7f1a0205517ee12355db7b347b478c611e3fad.zip
using reallocarray() gives us multiplicative integer overflow checking
in case something wants to create massive amounts of environment, like a bit more than 1/4 of a 32-bit address space. unrealistic -- but why audit one code path, and not treat others the same? then you have to re-engage everytime you see the code. read the news, that isn't what developers do. At least if the code paths look the same, there is hope, because they are easier to verify for correctness. developers need to give other developers a chance to want to care.
Diffstat (limited to 'lib/libc/stdlib/setenv.c')
-rw-r--r--lib/libc/stdlib/setenv.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c
index 9060fdba880..10b55445f76 100644
--- a/lib/libc/stdlib/setenv.c
+++ b/lib/libc/stdlib/setenv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setenv.c,v 1.14 2012/09/23 16:08:04 jeremy Exp $ */
+/* $OpenBSD: setenv.c,v 1.15 2014/10/08 05:33:31 deraadt Exp $ */
/*
* Copyright (c) 1987 Regents of the University of California.
* All rights reserved.
@@ -71,7 +71,7 @@ putenv(char *str)
for (P = environ; *P != NULL; P++)
;
cnt = P - environ;
- P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+ P = reallocarray(lastenv, cnt + 2, sizeof(char *));
if (!P)
return (-1);
if (lastenv != environ)
@@ -129,7 +129,7 @@ setenv(const char *name, const char *value, int rewrite)
for (P = environ; *P != NULL; P++)
;
cnt = P - environ;
- P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+ P = reallocarray(lastenv, cnt + 2, sizeof(char *));
if (!P)
return (-1);
if (lastenv != environ)