aboutsummaryrefslogtreecommitdiff
path: root/lib/env.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-05-02 18:41:11 -0700
committerRob Landley <rob@landley.net>2019-05-03 11:35:59 -0500
commitbd7c5c0555477d562bc7a4dab9561017a47b615e (patch)
tree42ae7a14d86c4ab011e52f6125c7ee95d733a0e2 /lib/env.c
parentd234c98318dc3e85c01092ddadfc9e7acddbbaef (diff)
downloadtoybox-bd7c5c0555477d562bc7a4dab9561017a47b615e.tar.gz
env: fix case where a variable is replaced.
Found when trying to update the toybox prebuilt used for the Android build. Also add the corresponding test.
Diffstat (limited to 'lib/env.c')
-rw-r--r--lib/env.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/lib/env.c b/lib/env.c
index 35ef688c..bc23b753 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -58,11 +58,9 @@ void xsetenv(char *name, char *val)
if (!memcmp(name, environ[i], len) && environ[i][len]=='=') {
if (i>=envc) free(environ[i]);
else {
- char **delete = environ+i;
-
// move old entries down, add at end of old data
toys.envc = envc--;
- for (i=0; new ? i<envc : !!delete[i]; i++) delete[i] = delete[i+1];
+ for (; new ? i<envc : !!environ[i]; i++) environ[i] = environ[i+1];
i = envc;
}
break;