This is the mail archive of the libc-alpha@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]

Re: [patch] Error on setenv(..., NULL, ...)


On Wed, Mar 11, 2015 at 10:14 AM, Joseph Myers <joseph@codesourcery.com> wrote:

> So, if it's undefined behavior to pass NULL here, any detection should
> take the form of an assertion.

Assert would be inconsistent with the other checks: it surely is just as
undefined to pass a NULL name.

I am fine with

  assert (name != NULL && *name != '\0' && value != NULL);
  if (strchr (name, '=') != NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }
...

but this may turn out to be too drastic.

The original check was added here:


Author: Roland McGrath <roland@gnu.org>
Date:   Wed Jun 9 18:33:36 2004 +0000

    * sysdeps/generic/setenv.c (setenv): Return -1/EINVAL if name is

        NULL, "" or contains '=' character in it.  Reported by
        Michael T Kerrisk <mtk-lists@gmx.net>.
        * stdlib/tst-environ.c: Include errno.h.
        (main): Add tests for these arguments to setenv/unsetenv.


+cc Roland, Michael
Thread starts here: https://sourceware.org/ml/libc-alpha/2015-03/msg00449.html

-- 
Paul Pluzhnikov


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