From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 29046385828E; Tue, 5 Jul 2022 04:50:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29046385828E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: spawn: Treat empty path as the current directory. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: b3e25f0bc1bf69bde17b0a8004d9ed4755ebd18a X-Git-Newrev: fc74dbf22f5c72f023713e7bb8c934ce34589163 Message-Id: <20220705045045.29046385828E@sourceware.org> Date: Tue, 5 Jul 2022 04:50:45 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 04:50:45 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dfc74dbf22f5= c72f023713e7bb8c934ce34589163 commit fc74dbf22f5c72f023713e7bb8c934ce34589163 Author: Takashi Yano Date: Mon Jun 27 21:34:01 2022 +0900 Cygwin: spawn: Treat empty path as the current directory. =20 - With this patch, the empty path (empty element in PATH or PATH is absent) is treated as the current directory as Linux does. This feature is added for Linux compatibility, but it is deprecated. POSIX notes that a conforming application shall use an explicit pathname to specify the current working directory. Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251730.html Diff: --- winsup/cygwin/release/3.4.0 | 4 ++++ winsup/cygwin/spawn.cc | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/release/3.4.0 b/winsup/cygwin/release/3.4.0 index 31b36dcfd..f310912c9 100644 --- a/winsup/cygwin/release/3.4.0 +++ b/winsup/cygwin/release/3.4.0 @@ -21,6 +21,10 @@ What changed: This aligns Cygwin behavior to that of Linux. Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251672.html =20 +- Treat an empty path (empty element in PATH or PATH is absent) as + the current directory as Linux does. + Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251730.html + =20 Bug Fixes --------- diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 8e700354a..277f0d1b3 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 =3D tp.c_get (); bool has_slash =3D !!strpbrk (name, "/\\"); int err =3D 0; + bool eopath =3D false; =20 debug_printf ("find_exec (%s)", name); =20 @@ -118,8 +119,14 @@ find_exec (const char *name, path_conv& buf, const cha= r *search, the name of an environment variable. */ if (strchr (search, '/')) *stpncpy (tmp, search, NT_MAX_PATH - 1) =3D '\0'; - else if (has_slash || isdrive (name) || !(path =3D getenv (search)) || != *path) + else if (has_slash || isdrive (name)) goto errout; + /* Search the current directory when PATH is absent. This feature is + added for Linux compatibility, but it is deprecated. POSIX notes + that a conforming application shall use an explicit path name to + specify the current working directory. */ + else if (!(path =3D getenv (search)) || !*path) + strcpy (tmp, "."); else *stpncpy (tmp, path, NT_MAX_PATH - 1) =3D '\0'; =20 @@ -130,11 +137,21 @@ find_exec (const char *name, path_conv& buf, const ch= ar *search, do { char *eotmp =3D strccpy (tmp_path, &path, ':'); + if (*path) + path++; + else + eopath =3D true; /* An empty path or '.' means the current directory, but we've already tried that. */ if ((opt & FE_CWD) && (tmp_path[0] =3D=3D '\0' || (tmp_path[0] =3D=3D '.' && tmp_path[1] =3D=3D '\0'))) continue; + /* An empty path means the current directory. This feature is + added for Linux compatibility, but it is deprecated. POSIX + notes that a conforming application shall use an explicit + pathname to specify the current working directory. */ + else if (tmp_path[0] =3D=3D '\0') + eotmp =3D stpcpy (tmp_path, "."); =20 *eotmp++ =3D '/'; stpcpy (eotmp, name); @@ -155,7 +172,7 @@ find_exec (const char *name, path_conv& buf, const char= *search, } =20 } - while (*path && *++path); + while (!eopath); =20 errout: /* Couldn't find anything in the given path.