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 11/03/15 16:33, Siddhesh Poyarekar wrote:
> 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:
> 

no, this just says that NULL argument is undefined behaviour

this is not a bug in glibc and i don't think any change should be made

> 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
> 


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