Cygwin's execlp() does not work with an empty $PATH element

Takashi Yano takashi.yano@nifty.ne.jp
Mon Jun 27 12:15:03 GMT 2022


On 2022年6月27日 20:16:36 +0900
Takashi Yano wrote:
> How about the following patch?

This is better a bit.
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index e0f1247e1..292cd5a42 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -95,6 +95,7 @@ find_exec (const char *name, path_conv& buf, const char *search,
 char *tmp = tp.c_get ();
 bool has_slash = !!strpbrk (name, "/\\");
 int err = 0;
+ bool eopath = false;
 
 debug_printf ("find_exec (%s)", name);
 
@@ -118,8 +119,10 @@ find_exec (const char *name, path_conv& buf, const char *search,
 the name of an environment variable. */
 if (strchr (search, '/'))
 *stpncpy (tmp, search, NT_MAX_PATH - 1) = '0円';
- else if (has_slash || isdrive (name) || !(path = getenv (search)) || !*path)
+ else if (has_slash || isdrive (name))
 goto errout;
+ else if (!(path = getenv (search)) || !*path)
+ strcpy (tmp, "."); /* Search the current directory when PATH is absent */
 else
 *stpncpy (tmp, path, NT_MAX_PATH - 1) = '0円';
 
@@ -130,11 +133,17 @@ find_exec (const char *name, path_conv& buf, const char *search,
 do
 {
 char *eotmp = strccpy (tmp_path, &path, ':');
+ if (*path)
+	path++;
+ else
+	eopath = true;
 /* An empty path or '.' means the current directory, but we've
 	 already tried that. */
 if ((opt & FE_CWD) && (tmp_path[0] == '0円'
 			 || (tmp_path[0] == '.' && tmp_path[1] == '0円')))
 	continue;
+ else if (tmp_path[0] == '0円') /* An empty path means the current dir. */
+	eotmp = stpcpy (tmp_path, ".");
 
 *eotmp++ = '/';
 stpcpy (eotmp, name);
@@ -155,7 +164,7 @@ find_exec (const char *name, path_conv& buf, const char *search,
 	}
 
 }
- while (*path && *++path);
+ while (!eopath);
 
 errout:
 /* Couldn't find anything in the given path.
-- 
Takashi Yano <takashi.yano@nifty.ne.jp>


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /