On 07/09/2018 09:16 AM, Chet Ramey wrote:
On 7/8/18 7:21 AM, Keeley Hoek wrote:
In running bash on an embedded target, bash crashes for the silly
reason that environ is NULL.
I haven't been able to tell whether this is actually permitted by the
standard (as if?), but in bash I think this behavior is inconsistent
anyway because:
It's probably permitted by the standard simply because the standard doesn't
specify the value of environ. As a practical matter, on Unix systems, even
when execve() is supplied a NULL third argument, environ is never null.
It's not unreasonable to check for it, though.
It's unspecified by the standard, so portable programs should not assume
it works. The only portable thing for emptying the environment is to
assign environ to a 1-element array containing a NULL pointer - but even
that is not portable as a completely empty environment wipes out PATH
and possibly other important variables (such as POSIXLY_CORRECT) that
may subtly break expectations.
That said, Cygwin was just recently patched to allow environ=NULL as
shorthand for emptying the environment:
https://cygwin.com/ml/cygwin-patches/2018-q2/msg00045.html
https://cygwin.com/ml/cygwin/2018-05/msg00334.html
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org