From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id F33493857436; Wed, 7 Jul 2021 08:47:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F33493857436 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: respect PC_SYM_FOLLOW and PC_SYM_NOFOLLOW_REP with inner links. X-Act-Checkin: newlib-cygwin X-Git-Author: Jeremy Drake X-Git-Refname: refs/heads/master X-Git-Oldrev: d0e42141b80739213be1c3c397edcce191e5b56e X-Git-Newrev: 4fca7b0da623cf109cf47468f34c8c4d4f59f6b2 Message-Id: <20210707084724.F33493857436@sourceware.org> Date: Wed, 7 Jul 2021 08:47:24 +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, 07 Jul 2021 08:47:25 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4fca7b0da623cf109cf47468f34c8c4d4f59f6b2 commit 4fca7b0da623cf109cf47468f34c8c4d4f59f6b2 Author: Jeremy Drake Date: Sat May 29 11:48:11 2021 -0700 Cygwin: respect PC_SYM_FOLLOW and PC_SYM_NOFOLLOW_REP with inner links. The new GetFinalPathNameW handling for native symlinks in inner path components is disabled if caller doesn't want to follow symlinks, or doesn't want to follow reparse points. Diff: --- winsup/cygwin/path.cc | 88 ++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index e62f8fe2b..1869fb8c8 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -722,9 +722,10 @@ path_conv::check (const char *src, unsigned opt, int symlen = 0; /* Make sure to check certain flags on last component only. */ - for (unsigned pc_flags = opt & (PC_NO_ACCESS_CHECK | PC_KEEP_HANDLE); + for (unsigned pc_flags = opt & (PC_NO_ACCESS_CHECK | PC_KEEP_HANDLE + | PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP); ; - pc_flags = 0) + pc_flags = opt & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) { const suffix_info *suff; char *full_path; @@ -3480,48 +3481,49 @@ restart: goto file_not_symlink; } #endif /* __i386__ */ - { - PWCHAR fpbuf = tp.w_get (); - DWORD ret; - - ret = GetFinalPathNameByHandleW (h, fpbuf, NT_MAX_PATH, 0); - if (ret) - { - UNICODE_STRING fpath; + if ((pc_flags & (PC_SYM_FOLLOW | PC_SYM_NOFOLLOW_REP)) == PC_SYM_FOLLOW) + { + PWCHAR fpbuf = tp.w_get (); + DWORD ret; - RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR)); - fpbuf[1] = L'?'; /* \\?\ --> \??\ */ - if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag)) - { - issymlink = true; - /* upath.Buffer is big enough and unused from this point on. - Reuse it here, avoiding yet another buffer allocation. */ - char *nfpath = (char *) upath.Buffer; - sys_wcstombs (nfpath, NT_MAX_PATH, fpbuf); - res = posixify (nfpath); - - /* If the incoming path consisted of a drive prefix only, - we just handle a virtual drive, created with, e.g. - - subst X: C:\foo\bar - - Treat it like a symlink. This is required to tell an - lstat caller that the "drive" is actually pointing - somewhere else, thus, it's a symlink in POSIX speak. */ - if (upath.Length == 14) /* \??\X:\ */ - { - fileattr &= ~FILE_ATTRIBUTE_DIRECTORY; - path_flags |= PATH_SYMLINK; - } - /* For final paths differing in inner path components return - length as negative value. This informs path_conv::check - to skip realpath handling on the last path component. */ - else - res = -res; - break; - } - } - } + ret = GetFinalPathNameByHandleW (h, fpbuf, NT_MAX_PATH, 0); + if (ret) + { + UNICODE_STRING fpath; + + RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR)); + fpbuf[1] = L'?'; /* \\?\ --> \??\ */ + if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag)) + { + issymlink = true; + /* upath.Buffer is big enough and unused from this point on. + Reuse it here, avoiding yet another buffer allocation. */ + char *nfpath = (char *) upath.Buffer; + sys_wcstombs (nfpath, NT_MAX_PATH, fpbuf); + res = posixify (nfpath); + + /* If the incoming path consisted of a drive prefix only, + we just handle a virtual drive, created with, e.g. + + subst X: C:\foo\bar + + Treat it like a symlink. This is required to tell an + lstat caller that the "drive" is actually pointing + somewhere else, thus, it's a symlink in POSIX speak. */ + if (upath.Length == 14) /* \??\X:\ */ + { + fileattr &= ~FILE_ATTRIBUTE_DIRECTORY; + path_flags |= PATH_SYMLINK; + } + /* For final paths differing in inner path components return + length as negative value. This informs path_conv::check + to skip realpath handling on the last path component. */ + else + res = -res; + break; + } + } + } /* Normal file. */ file_not_symlink: