This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/13231] New: setenv ("NAME", NULL) corrupts environment
- From: "robert.ancell at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Wed, 28 Sep 2011 05:23:32 +0000
- Subject: [Bug libc/13231] New: setenv ("NAME", NULL) corrupts environment
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=13231
Bug #: 13231
Summary: setenv ("NAME", NULL) corrupts environment
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper.fsp@gmail.com
ReportedBy: robert.ancell@gmail.com
Classification: Unclassified
Created attachment 5948
--> http://sourceware.org/bugzilla/attachment.cgi?id=5948
Proposed patch, which treats NULL value as "" (which I think is what the
current code intends).
setenv ("NAME", NULL) corrupts the environment. It doesn't seem specified what
the function should do when value is NULL, but the code does check for it - it
just does the wrong thing:
stdlib/setenv.c:
...
__add_to_environ (name, value, combined, replace)
...
const size_t vallen = value != NULL ? strlen (value) + 1 : 0;
...
memcpy (new_value, name, namelen);
new_value[namelen] = '=';
memcpy (&new_value[namelen + 1], value, vallen);
...
i.e. the new value is set to "NAME=" without the trailing nul character.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.