public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: skip native symlink check in Windows dir under WOW64
Date: Wed, 21 Apr 2021 15:41:30 +0000 (GMT)	[thread overview]
Message-ID: <20210421154130.263463838001@sourceware.org> (raw)

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


                 reply	other threads:[~2021-04-21 15:41 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=20210421154130.263463838001@sourceware.org \
    --to=corinna@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).