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

Joseph Myers joseph@codesourcery.com
Wed Mar 11 17:14:00 GMT 2015


On Wed, 11 Mar 2015, Paul Pluzhnikov wrote:

> Attached trivial patch makes setenv(..., NULL, ...) fail instead of
> producing "bad" environment. Tested on Linux/x86_64, no new failures.

The conventions at 
<https://sourceware.org/glibc/wiki/Style_and_Conventions#Error_Handling> 
say that "If it's user code invoking undefined behavior, then it should 
fail early and catastrophically ... That too trades off against any 
runtime cost of detecting the case.".  And, more specifically for null 
pointers, "If you're going to check for NULL pointer arguments where you 
have not entered into a contract to accept and interpret them, do so with 
an assert, not a conditional error return.".

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

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Libc-alpha mailing list