public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive.
@ 2022-02-03  8:40 Takashi Yano
  2022-02-03  8:58 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Takashi Yano @ 2022-02-03  8:40 UTC (permalink / raw)
  To: cygwin-patches

- 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 | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 87ac2404a..4ad4e0821 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -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))
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-03 11:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03  8:40 [PATCH] Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive Takashi Yano
2022-02-03  8:58 ` Corinna Vinschen
2022-02-03  9:28   ` Takashi Yano
2022-02-03 10:59     ` Takashi Yano
2022-02-03 11:36       ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).