public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive.
Date: Thu,  3 Feb 2022 09:30:34 +0000 (GMT)	[thread overview]
Message-ID: <20220203093034.503F43858C2C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=71d5490a3a2d769e1893f11c98edb06468ad6af4

commit 71d5490a3a2d769e1893f11c98edb06468ad6af4
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Thu Feb 3 12:00:14 2022 +0900

    Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive.
    
    - 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.

Diff:
---
 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))


                 reply	other threads:[~2022-02-03  9:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220203093034.503F43858C2C@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).