diff options
author | ache <ache@FreeBSD.org> | 2012-10-02 17:44:08 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2012-10-02 17:44:08 +0000 |
commit | 001794b735018a8bbdbac013a520940cd521bb71 (patch) | |
tree | 4e2ac684c11f1edbdfd30f0799fdb6efbc4da0a6 /lib/libc/stdlib/getenv.c | |
parent | 88359df5bb65c7855c6aaa313e13958aae6c7a18 (diff) | |
download | FreeBSD-src-001794b735018a8bbdbac013a520940cd521bb71.zip FreeBSD-src-001794b735018a8bbdbac013a520940cd521bb71.tar.gz |
Using putenv() and later direct pointer contents modification it is possibe
to craft environment variables with similar names like that:
a=1
a=2
...
unsetenv("a") should remove them all to make later getenv("a") impossible.
Fix it to do so (this is GNU autoconf test #3 failure too).
PR: 172273
MFC after: 1 week
Diffstat (limited to 'lib/libc/stdlib/getenv.c')
-rw-r--r-- | lib/libc/stdlib/getenv.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c index b7826d7..37602a9 100644 --- a/lib/libc/stdlib/getenv.c +++ b/lib/libc/stdlib/getenv.c @@ -675,11 +675,13 @@ unsetenv(const char *name) /* Deactivate specified variable. */ envNdx = envVarsTotal - 1; - if (__findenv(name, nameLen, &envNdx, true) != NULL) { + /* Remove all occurrences. */ + while (__findenv(name, nameLen, &envNdx, true) != NULL) { envVars[envNdx].active = false; if (envVars[envNdx].putenv) __remove_putenv(envNdx); __rebuild_environ(envActive - 1); + envNdx = envVarsTotal - 1; } return (0); |