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.
This commit is contained in:
Takashi Yano 2021-12-09 17:15:23 +09:00
parent 1b40f151cd
commit c2f39a543e
1 changed files with 35 additions and 21 deletions

View File

@ -3507,29 +3507,43 @@ restart:
if (RtlEqualUnicodePathPrefix (&fpath, &ro_u_uncp, TRUE) if (RtlEqualUnicodePathPrefix (&fpath, &ro_u_uncp, TRUE)
&& !RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE)) && !RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE))
{ {
/* ...get the remote path from the volume path name, /* ...get the remote path, replace remote path
replace remote path with drive letter, check again. */ with drive letter, check again. */
WCHAR drive[3] =
{(WCHAR) towupper (upath.Buffer[4]), L':', L'\0'};
WCHAR remote[MAX_PATH]; WCHAR remote[MAX_PATH];
fpbuf[1] = L'\\';
BOOL r = GetVolumePathNameW (fpbuf, remote, MAX_PATH); int remlen = QueryDosDeviceW (drive, remote, MAX_PATH);
fpbuf[1] = L'?'; if (remlen < 3)
if (r) goto file_not_symlink; /* fallback */
{ remlen -= 2;
int remlen = wcslen (remote);
if (remote[remlen - 1] == L'\\') if (remote[remlen - 1] == L'\\')
remlen--; remlen--;
/* Hackfest */ WCHAR *p;
fpath.Buffer[4] = upath.Buffer[4]; /* Drive letter */ UNICODE_STRING rpath;
fpath.Buffer[5] = L':'; RtlInitCountedUnicodeString (&rpath, remote,
WCHAR *to = fpath.Buffer + 6; remlen * sizeof (WCHAR));
WCHAR *from = to + remlen - 6; if (RtlEqualUnicodePathPrefix (&rpath, &ro_u_uncp, TRUE))
memmove (to, from, remlen -= 6;
(wcslen (from) + 1) * sizeof (WCHAR)); else if ((p = wcschr (remote, L';'))
fpath.Length -= (from - to) * sizeof (WCHAR); && p + 3 < remote + remlen
if (RtlEqualUnicodeString (&upath, &fpath, !!ci_flag)) && wcsncmp (p + 1, drive, 2) == 0
goto file_not_symlink; && (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; issymlink = true;
/* upath.Buffer is big enough and unused from this point on. /* upath.Buffer is big enough and unused from this point on.