From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 3F9983858C2C; Thu, 3 Feb 2022 09:30:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F9983858C2C 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: 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/master X-Git-Oldrev: 4a70041dfd3e42f743ef21d788be65e7fac7e9e7 X-Git-Newrev: e5aca9ced94c1e42390f1d0a2fd7eb2ae09bd5a3 Message-Id: <20220203093007.3F9983858C2C@sourceware.org> Date: Thu, 3 Feb 2022 09:30:07 +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:07 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3De5aca9ced94= c1e42390f1d0a2fd7eb2ae09bd5a3 commit e5aca9ced94c1e42390f1d0a2fd7eb2ae09bd5a3 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))