public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: skip native symlink check in Windows dir under WOW64
@ 2021-04-21 15:41 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2021-04-21 15:41 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 13fd26ecf5ca8417146d57b45aed0133435c3497
Author: Corinna Vinschen <corinna@vinschen.de>
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 <corinna@vinschen.de>

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-21 15:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 15:41 [newlib-cygwin] Cygwin: skip native symlink check in Windows dir under WOW64 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).