| Summary: | unsetenv(3) issue according to autoconf | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | Ed Maste <emaste> | ||||||
| Component: | standards | Assignee: | Andrey A. Chernov <ache> | ||||||
| Status: | Closed FIXED | ||||||||
| Severity: | Affects Only Me | ||||||||
| Priority: | Normal | ||||||||
| Version: | 9.1-PRERELEASE | ||||||||
| Hardware: | Any | ||||||||
| OS: | Any | ||||||||
| Attachments: |
|
||||||||
Attached simple patch should fix this issue (failing on test 3). > Attached simple patch should fix this issue (failing on test 3).
Thanks, that fixes it.
Your comment is missing a . and occurrences has two 'r's though.
-Ed
On 02.10.2012 20:08, Andrey Chernov wrote:
> Attached simple patch should fix this issue (failing on test 3).
Oops, see more correct version attached.
Author: ache Date: Tue Oct 2 17:44:08 2012 New Revision: 241137 URL: http://svn.freebsd.org/changeset/base/241137 Log: 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 Modified: head/lib/libc/stdlib/getenv.c Modified: head/lib/libc/stdlib/getenv.c ============================================================================== --- head/lib/libc/stdlib/getenv.c Tue Oct 2 17:05:20 2012 (r241136) +++ head/lib/libc/stdlib/getenv.c Tue Oct 2 17:44:08 2012 (r241137) @@ -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); _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" State Changed From-To: open->patched assign and set as MFC reminder. Responsible Changed From-To: freebsd-standards->ache State Changed From-To: patched->closed Committed into stable |
How-To-Repeat: The autoconf test is reproduced below - the 'return 3' is the failing line #include <stdlib.h> #include <errno.h> extern char **environ; int main(int argc, char *argv[]) { char entry1[] = "a=1"; char entry2[] = "b=2"; char *env[] = { entry1, entry2, NULL }; if (putenv ((char *) "a=1")) return 1; if (putenv (entry2)) return 2; entry2[0] = 'a'; unsetenv ("a"); if (getenv ("a")) return 3; if (!unsetenv ("") || errno != EINVAL) return 4; entry2[0] = 'b'; environ = env; if (!getenv ("a")) return 5; entry2[0] = 'a'; unsetenv ("a"); if (getenv ("a")) return 6; return 0; }