This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/13231] New: setenv ("NAME", NULL) corrupts environment


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]