]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive.
authorTakashi Yano <takashi.yano@nifty.ne.jp>
Thu, 3 Feb 2022 03:00:14 +0000 (12:00 +0900)
committerTakashi Yano <takashi.yano@nifty.ne.jp>
Thu, 3 Feb 2022 03:21:21 +0000 (12:21 +0900)
- If an UNC path is mounted to a drive using SMB3.11, accessing to
  the drive fails with error "Too many levels of symbolic links."
  This patch fixes the issue.

winsup/cygwin/path.cc

index 87ac2404aa928e9a24222ab96b3640f26da958b6..4ad4e0821d9467e246a9652ed67bcbabbf9d2388 100644 (file)
@@ -3495,10 +3495,19 @@ restart:
 
              /* If incoming path has no trailing backslash, but final path
                 has one, drop trailing backslash from final path so the
-                below string comparison has a chance to succeed. */
+                below string comparison has a chance to succeed.
+                On the contrary, if incoming path has trailing backslash,
+                but final path does not have one, add trailing backslash
+                to the final path. */
              if (upath.Buffer[(upath.Length - 1) / sizeof (WCHAR)] != L'\\'
-                  && fpbuf[ret - 1] == L'\\')
+                 && fpbuf[ret - 1] == L'\\')
                 fpbuf[--ret] = L'\0';
+             if (upath.Buffer[(upath.Length - 1) / sizeof (WCHAR)] == L'\\'
+                 && fpbuf[ret - 1] != L'\\' && ret < NT_MAX_PATH - 1)
+               {
+                 fpbuf[ret++] = L'\\';
+                 fpbuf[ret] = L'\0';
+               }
              fpbuf[1] = L'?';  /* \\?\ --> \??\ */
              RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
              if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
This page took 0.036146 seconds and 5 git commands to generate.