From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 503F43858C2C; Thu, 3 Feb 2022 09:30:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 503F43858C2C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 699ff18953d501b9085d07867edea4500b1da478 X-Git-Newrev: 71d5490a3a2d769e1893f11c98edb06468ad6af4 Message-Id: <20220203093034.503F43858C2C@sourceware.org> Date: Thu, 3 Feb 2022 09:30:34 +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: Thu, 03 Feb 2022 09:30:34 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D71d5490a3a2= d769e1893f11c98edb06468ad6af4 commit 71d5490a3a2d769e1893f11c98edb06468ad6af4 Author: Takashi Yano Date: Thu Feb 3 12:00:14 2022 +0900 Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive. =20 - 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: =20 /* 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)] !=3D L'\\' - && fpbuf[ret - 1] =3D=3D L'\\') + && fpbuf[ret - 1] =3D=3D L'\\') fpbuf[--ret] =3D L'\0'; + if (upath.Buffer[(upath.Length - 1) / sizeof (WCHAR)] =3D=3D L'\\' + && fpbuf[ret - 1] !=3D L'\\' && ret < NT_MAX_PATH - 1) + { + fpbuf[ret++] =3D L'\\'; + fpbuf[ret] =3D L'\0'; + } fpbuf[1] =3D L'?'; /* \\?\ --> \??\ */ RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR)); if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))