This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Cannot exec() program outside of /bin if PATH is unset
- From: Christian Franke <Christian dot Franke at t-online dot de>
- To: cygwin at cygwin dot com
- Date: Fri, 12 Sep 2014 19:02:19 +0200
- Subject: Cannot exec() program outside of /bin if PATH is unset
- Authentication-results: sourceware.org; auth=none
If PATH variable is unset or does not contain /bin or /usr/bin,
exec("/not_bin/program", ...) fails because cygwin DLLs could not be loaded.
This affects postfix which cleans the environment to the bare minimum
for security reasons.
(fortunately there is an easy workaround, so this does not block postfix
ITP)
Testcase:
$ cat nopath.cc
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// #include <windows.h>
int main()
{
unsetenv("PATH");
// SetDllDirectory("c:\\cygwin\\bin");
execl("/usr/sbin/alternatives", "alternatives", (const char*)0);
perror("execl");
return 1;
}
$ make nopath
...
$ ./nopath
/usr/sbin/alternatives.exe: error while loading shared libraries: ?:
cannot open shared object file: No such file or directory
Enabling the SetDllDirectory() Win32 call fixes the problem.
Would possibly make sense to add this call to cygwin1.dll.
Christian
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple