From 3b82917a49f9e5ec3f6d4868adeac35a52c5a06e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 26 Feb 2020 02:45:09 -0600 Subject: Fix xclearenv() breakage pointed out by Derrick Pallas. Toybox doesn't modify inherited environ[] (the same way we don't modify our inherited argv[]), so instead of freeing our allocated environ[] when we want to clear it we need to allocate a new environ[] in the else path (at a length compatible with the existing plumbing's add stride), set the first entry of _that_ to 0, and set toys.envc = 1 to record it's an alloced environ. --- lib/env.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/env.c b/lib/env.c index 92cc811f..614a504c 100644 --- a/lib/env.c +++ b/lib/env.c @@ -2,7 +2,7 @@ #include "toys.h" -// In libc, populated by start code,used by getenv() and exec() and friends. +// In libc, populated by start code, used by getenv() and exec() and friends. extern char **environ; // Returns the number of bytes taken by the environment variables. For use @@ -26,9 +26,8 @@ void xclearenv(void) int i; for (i = 0; environ[i]; i++) if (i>=toys.envc) free(environ[i]); - free(environ); - } - toys.envc = 0; + } else environ = xmalloc(256*sizeof(char *)); + toys.envc = 1; *environ = 0; } -- cgit v1.2.3