mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
libc/stdlib/getenv.c: always allocate new environment
in particular, if the old environment is NULL. Among making it less surprising for userspace to observe NULL environ, the change also prevents NULL deref in __rebuild_environ() when terminating the empty as NULL environment with the NULL pointer. Reported by: Leo Bicknell <[email protected]> PR: 298747 Reviewed by: emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D59996
This commit is contained in:
1 parent
782c6ea086
commit
dec68aeff8
1 file changed
+1
-1
@@ -268,7 +268,7 @@ __rebuild_environ(int newEnvironSize)
|
||||
int tmpEnvironSize;
|
||||
|
||||
/* Resize environ. */
|
||||
if (newEnvironSize > environSize) {
|
||||
if (newEnvironSize > environSize || intEnviron == NULL) {
|
||||
tmpEnvironSize = newEnvironSize * 2;
|
||||
tmpEnviron = reallocarray(intEnviron, tmpEnvironSize + 1,
|
||||
sizeof(*intEnviron));
|
||||
|
||||
Reference in new issue
Block a user