public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "robert.ancell at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/13231] New: setenv ("NAME", NULL) corrupts environment
Date: Wed, 28 Sep 2011 05:24:00 -0000	[thread overview]
Message-ID: <bug-13231-131@http.sourceware.org/bugzilla/> (raw)

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.


             reply	other threads:[~2011-09-28  5:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-28  5:24 robert.ancell at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-13231-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).