From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id B0EBE3858D1E; Wed, 10 Aug 2022 11:50:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0EBE3858D1E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: fix return value of symlink_info::check X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 34872ce1a11e3c24154dc2d2ab90c5eb6da47edb X-Git-Newrev: 5cdf8ade2882b87b29d6fa66451b5d5497fa96b2 Message-Id: <20220810115046.B0EBE3858D1E@sourceware.org> Date: Wed, 10 Aug 2022 11:50:46 +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: Wed, 10 Aug 2022 11:50:46 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D5cdf8ade288= 2b87b29d6fa66451b5d5497fa96b2 commit 5cdf8ade2882b87b29d6fa66451b5d5497fa96b2 Author: Ken Brown Date: Tue Aug 9 15:14:07 2022 -0400 Cygwin: fix return value of symlink_info::check =20 Currently it is possible for symlink_info::check to return -1 in case we're searching for foo and find foo.lnk that is not a Cygwin symlink. This contradicts the new meaning attached to a negative return value in commit 19d59ce75d. Fix this by setting "res" to 0 at the beginning of the main loop and not seting it to -1 later. =20 Also fix the commentary preceding the function definition to reflect the current behavior. =20 Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252030.html Diff: --- winsup/cygwin/path.cc | 22 +++++++++------------- winsup/cygwin/release/3.3.6 | 4 ++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 3e436dc65..227b99d0f 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3027,19 +3027,16 @@ symlink_info::parse_device (const char *contents) /* Check if PATH is a symlink. PATH must be a valid Win32 path name. =20 If PATH is a symlink, put the value of the symlink--the file to - which it points--into BUF. The value stored in BUF is not - necessarily null terminated. BUFLEN is the length of BUF; only up - to BUFLEN characters will be stored in BUF. BUF may be NULL, in - which case nothing will be stored. + which it points--into CONTENTS. =20 - Set *SYML if PATH is a symlink. + Set PATH_SYMLINK if PATH is a symlink. =20 - Set *EXEC if PATH appears to be executable. This is an efficiency - hack because we sometimes have to open the file anyhow. *EXEC will - not be set for every executable file. - - Return -1 on error, 0 if PATH is not a symlink, or the length - stored into BUF if PATH is a symlink. */ + If PATH is a symlink, return the length stored into CONTENTS. If + the inner components of PATH contain native symlinks or junctions, + or if the drive is a virtual drive, compare PATH with the result + returned by GetFinalPathNameByHandleA. If they differ, store the + final path in CONTENTS and return the negative of its length. In + all other cases, return 0. */ =20 int symlink_info::check (char *path, const suffix_info *suffixes, fs_info &fs, @@ -3094,6 +3091,7 @@ restart: =20 while (suffix.next ()) { + res =3D 0; error =3D 0; get_nt_native_path (suffix.path, upath, mount_flags & MOUNT_DOS); if (h) @@ -3345,8 +3343,6 @@ restart: continue; } =20 - res =3D -1; - /* Reparse points are potentially symlinks. This check must be performed before checking the SYSTEM attribute for sysfile symlinks, since reparse points can have this flag set, too. */ diff --git a/winsup/cygwin/release/3.3.6 b/winsup/cygwin/release/3.3.6 index 078e6e520..364e0cb0d 100644 --- a/winsup/cygwin/release/3.3.6 +++ b/winsup/cygwin/release/3.3.6 @@ -35,3 +35,7 @@ Bug Fixes - Fix a problem that prevented some symbolic links to /cygdrive/C, /cygdrive/./c, /cygdrive//c, etc. from working. Addresses: https://cygwin.com/pipermail/cygwin/2022-July/251994.html + +- Fix a path handling bug that could cause a non-existing file to be + treated as the current directory. + Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252030.html