public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/13231] New: setenv ("NAME", NULL) corrupts environment
@ 2011-09-28  5:24 robert.ancell at gmail dot com
  2011-09-28  5:24 ` [Bug libc/13231] " robert.ancell at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: robert.ancell at gmail dot com @ 2011-09-28  5:24 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-06-27 12:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-28  5:24 [Bug libc/13231] New: setenv ("NAME", NULL) corrupts environment robert.ancell at gmail dot com
2011-09-28  5:24 ` [Bug libc/13231] " robert.ancell at gmail dot com
2011-10-15 14:17 ` drepper.fsp at gmail dot com
2011-10-16 22:04 ` robert.ancell at gmail dot com
2011-10-29 20:19 ` drepper.fsp at gmail dot com
2011-10-29 23:17 ` ldv at altlinux dot org
2014-06-27 12:01 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).