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

Siddhesh Poyarekar siddhesh@redhat.com
Wed Mar 11 16:33:00 GMT 2015


On Wed, Mar 11, 2015 at 09:11:59AM -0700, Paul Pluzhnikov wrote:
> Attached trivial patch makes setenv(..., NULL, ...) fail instead of
> producing "bad" environment. Tested on Linux/x86_64, no new failures.

The standard says[1]:

"The environment variable shall be set to the value to which envval points"

and is vague since it could be interpreted in one of two ways:

1. setenv (..., NULL, ...) is equivalent to unsetting the environment
   variable, since getenv(...) would return NULL.

2. setenv (..., NULL, ...) is equivalent to setenv (..., "", ...),
   resulting in getenv returning a blank value.

Making it fail would be incorrect since it could break programs that
did not previously expect a failure from an invalid value and will
also not conform to the standard since the standard does not specify
such a failure.  While Option 1 seems closer to the above statement to
me, Option 2 seems like a safer fix.

Siddhesh

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/setenv.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150311/886dbed8/attachment.sig>


More information about the Libc-alpha mailing list