From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 5EF9C385840A; Sat, 11 Dec 2021 14:10:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EF9C385840A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: path: Fix path conversion of virtual drive. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 1b40f151cd5ad86241e98fe3b60d4700f04bfb99 X-Git-Newrev: c2f39a543e2b4a8a136a629fbf24fe75be57a26f Message-Id: <20211211141000.5EF9C385840A@sourceware.org> Date: Sat, 11 Dec 2021 14:10:00 +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: Sat, 11 Dec 2021 14:10:00 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c2f39a543e2b4a8a136a629fbf24fe75be57a26f commit c2f39a543e2b4a8a136a629fbf24fe75be57a26f Author: Takashi Yano Date: Thu Dec 9 17:15:23 2021 +0900 Cygwin: path: Fix path conversion of virtual drive. - The last change in path.cc introduced a bug that causes an error when accessing a virtual drive which mounts UNC path such as "\\server\share\dir" rather than "\\server\share". This patch fixes the issue. Diff: --- winsup/cygwin/path.cc | 56 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index eb1255849..5ab75f105 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3507,29 +3507,43 @@ restart: if (RtlEqualUnicodePathPrefix (&fpath, &ro_u_uncp, TRUE) && !RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE)) { - /* ...get the remote path from the volume path name, - replace remote path with drive letter, check again. */ + /* ...get the remote path, replace remote path + with drive letter, check again. */ + WCHAR drive[3] = + {(WCHAR) towupper (upath.Buffer[4]), L':', L'\0'}; WCHAR remote[MAX_PATH]; - fpbuf[1] = L'\\'; - BOOL r = GetVolumePathNameW (fpbuf, remote, MAX_PATH); - fpbuf[1] = L'?'; - if (r) - { - int remlen = wcslen (remote); - if (remote[remlen - 1] == L'\\') - remlen--; - /* Hackfest */ - fpath.Buffer[4] = upath.Buffer[4]; /* Drive letter */ - fpath.Buffer[5] = L':'; - WCHAR *to = fpath.Buffer + 6; - WCHAR *from = to + remlen - 6; - memmove (to, from, - (wcslen (from) + 1) * sizeof (WCHAR)); - fpath.Length -= (from - to) * sizeof (WCHAR); - if (RtlEqualUnicodeString (&upath, &fpath, !!ci_flag)) - goto file_not_symlink; - } + + int remlen = QueryDosDeviceW (drive, remote, MAX_PATH); + if (remlen < 3) + goto file_not_symlink; /* fallback */ + remlen -= 2; + + if (remote[remlen - 1] == L'\\') + remlen--; + WCHAR *p; + UNICODE_STRING rpath; + RtlInitCountedUnicodeString (&rpath, remote, + remlen * sizeof (WCHAR)); + if (RtlEqualUnicodePathPrefix (&rpath, &ro_u_uncp, TRUE)) + remlen -= 6; + else if ((p = wcschr (remote, L';')) + && p + 3 < remote + remlen + && wcsncmp (p + 1, drive, 2) == 0 + && (p = wcschr (p + 3, L'\\'))) + remlen -= p - remote - 1; + else + goto file_not_symlink; /* fallback */ + /* Hackfest */ + fpath.Buffer[4] = drive[0]; /* Drive letter */ + fpath.Buffer[5] = L':'; + WCHAR *to = fpath.Buffer + 6; + WCHAR *from = to + remlen; + memmove (to, from, + (wcslen (from) + 1) * sizeof (WCHAR)); + fpath.Length -= (from - to) * sizeof (WCHAR); + if (RtlEqualUnicodeString (&upath, &fpath, !!ci_flag)) + goto file_not_symlink; } issymlink = true; /* upath.Buffer is big enough and unused from this point on.