Cannot exec() program outside of /bin if PATH is unset

Eric Blake eblake@redhat.com
Fri Sep 12 22:50:00 GMT 2014


On 09/12/2014 02:15 PM, Christian Franke wrote:
>>>    unsetenv("PATH");
>> This is undefined behavior, per POSIX.  POSIX recommends that you always
>> leave PATH defined to at least a bare minimum of the results of
>> confstr(_CS_PATH, ...); it also states that implementations are free to
>> do what they want (in this case, crash) if you don't follow the
>> recommendation:
>>
>> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html
>> "If PATH is unset or is set to null, the path search is
>> implementation-defined."
> 
> There is no POSIX PATH search needed in my testcase:
>   execl("/usr/sbin/alternatives", ...)

PATH may not be needed for execl() to find the binary it will be
executing, but it IS required to be set in the environment to the bare
minimum of confstr(_CS_PATH) for that binary to have a chance of
executing in a well-defined setup.

> 
> The alternatives.exe could be found. The required DLLs could not be loaded.
> POSIX does not specify anything about the load path of shared libraries.
> On Linux, LD_LIBRARY_PATH is completely separate from PATH.
> On Windows, the DLL load path is connected to PATH.
> 
>>> Enabling the SetDllDirectory() Win32 call fixes the problem.
>>> Would possibly make sense to add this call to cygwin1.dll.
>> That said, just because POSIX has already given us the
>> get-out-of-jail-free card doesn't mean that we can't be nice and improve
>> cygwin1.dll to try and help broken programs that unset PATH.
> 
> Hmm... is postfix actually broken?

Yes, from the POSIX point of view.  It is doing something that is
documented to have unspecified behavior, namely, removing PATH from the
environment.

> Unsetting PATH is IMO sane (from the POSIX POV) if all exec() calls use
> absolute path names.

It is unspecified, whether or not it has sane behavior on some
platforms.  Just because something is unspecified by POSIX doesn't mean
that you can't do it, it just means that if you do it, and things break,
you get to keep both pieces.

So I would file a bug to upstream postfix that they are broken for
unsetting PATH.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 539 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140912/34d54fe5/attachment.sig>


More information about the Cygwin mailing list