From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 263463838001; Wed, 21 Apr 2021 15:41:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 263463838001 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: skip native symlink check in Windows dir under WOW64 X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 282445a10ebda592a0bb0e947725e1205b8436d3 X-Git-Newrev: 13fd26ecf5ca8417146d57b45aed0133435c3497 Message-Id: <20210421154130.263463838001@sourceware.org> Date: Wed, 21 Apr 2021 15:41:30 +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: Wed, 21 Apr 2021 15:41:30 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=13fd26ecf5ca8417146d57b45aed0133435c3497 commit 13fd26ecf5ca8417146d57b45aed0133435c3497 Author: Corinna Vinschen Date: Wed Apr 21 17:32:06 2021 +0200 Cygwin: skip native symlink check in Windows dir under WOW64 Commit 456c3a46386f added a workaround when handling paths with native symlinks as inner path components. This patch introduced a problem for paths handled by the WOW64 File System Redirector (FSR). Fix this problem by not performing the new code from commit 456c3a46386f for paths under the Windows directory. Only do this in WOW64. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/dcrt0.cc | 6 ++++++ winsup/cygwin/globals.cc | 2 ++ winsup/cygwin/path.cc | 30 ++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index f153c732b..3bbee4d5a 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -730,6 +730,12 @@ init_windows_system_directory () system_wow64_directory[system_wow64_directory_length++] = L'\\'; system_wow64_directory[system_wow64_directory_length] = L'\0'; } + /* We need the Windows dir in path.cc. */ + wcscpy (windows_directory, windows_system_directory); + windows_directory_length = windows_system_directory_length - 1; + windows_directory[windows_directory_length] = L'\0'; + while (windows_directory[windows_directory_length - 1] != L'\\') + windows_directory[--windows_directory_length] = L'\0'; #endif /* __i386__ */ } } diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc index 942bd1c83..0b9559ea7 100644 --- a/winsup/cygwin/globals.cc +++ b/winsup/cygwin/globals.cc @@ -26,6 +26,8 @@ UINT windows_system_directory_length; #ifdef __i386__ WCHAR system_wow64_directory[MAX_PATH]; UINT system_wow64_directory_length; +WCHAR windows_directory[MAX_PATH]; +UINT windows_directory_length; #endif /* __i386__ */ WCHAR global_progname[NT_MAX_PATH]; diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 2248b564b..93068a4dc 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3187,9 +3187,31 @@ restart: forces path_conv::check to backtrack inner path components. */ if (!fs.is_remote_drive ()) { - PFILE_NAME_INFORMATION pfni = (PFILE_NAME_INFORMATION) - tp.c_get (); +#ifdef __i386__ + /* On WOW64, ignore any potential problems if the path is inside + the Windows dir to avoid false positives for stuff under + File System Redirector control. */ + if (wincap.is_wow64 ()) + { + static UNICODE_STRING wpath; + UNICODE_STRING udpath; + + /* Create UNICODE_STRING for Windows dir. */ + RtlInitCountedUnicodeString (&wpath, windows_directory, + windows_directory_length * sizeof (WCHAR)); + /* Create a UNICODE_STRING from incoming path, splitting + off the leading "\\??\\" */ + RtlInitCountedUnicodeString (&udpath, upath.Buffer + 4, + upath.Length - 4 * sizeof (WCHAR)); + /* Are we below Windows dir? Skip the check for inner + symlinks. */ + if (RtlEqualUnicodePathPrefix (&udpath, &wpath, TRUE)) + goto skip_inner_syml_check; + } +#endif /* __i386__ */ + PFILE_NAME_INFORMATION pfni; + pfni = (PFILE_NAME_INFORMATION) tp.c_get (); if (NT_SUCCESS (NtQueryInformationFile (h, &io, pfni, NT_MAX_PATH, FileNameInformation))) { @@ -3204,6 +3226,10 @@ restart: break; } } +#ifdef __i386__ + skip_inner_syml_check: + ; +#endif /* __i386__ */ } } if (!NT_SUCCESS (status))