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: path_conv: Try to handle native symlinks more sanely
Date: Mon, 19 Apr 2021 12:55:00 +0000 (GMT)	[thread overview]
Message-ID: <20210419125500.402EE386FC2B@sourceware.org> (raw)

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

commit 456c3a46386f38887407603b2c64b7f63a4871c5
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Mon Apr 19 14:49:14 2021 +0200

    Cygwin: path_conv: Try to handle native symlinks more sanely
    
    For local paths, add a check if the inner path components contain native
    symlinks or junctions.  Compare the incoming path with the path returned
    by NtQueryInformationFile(FileNameInformation).  If they differ, there
    must be at least one native symlink or junction in the path.  If so,
    treat the currently evaluated file as non-existant.  This forces
    path_conv::check to backtrack inner path components until we eliminated
    all native symlinks or junctions and have a normalized path.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/path.cc | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 1d6bcbe48..2248b564b 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3179,6 +3179,32 @@ restart:
 	  status = conv_hdl.get_finfo (h, fs.is_nfs ());
 	  if (NT_SUCCESS (status))
 	    fileattr = conv_hdl.get_dosattr (fs.is_nfs ());
+
+	  /* For local paths, check if the inner path components contain
+	     native symlinks or junctions.  Compare incoming path with
+	     path returned by NtQueryInformationFile(FileNameInformation).
+	     If they differ, bail out as if the file doesn't exist.  This
+	     forces path_conv::check to backtrack inner path components. */
+	  if (!fs.is_remote_drive ())
+	    {
+	      PFILE_NAME_INFORMATION pfni = (PFILE_NAME_INFORMATION)
+					    tp.c_get ();
+
+	      if (NT_SUCCESS (NtQueryInformationFile (h, &io, pfni, NT_MAX_PATH,
+						      FileNameInformation)))
+		{
+		  UNICODE_STRING npath;
+
+		  RtlInitCountedUnicodeString (&npath, pfni->FileName,
+					      pfni->FileNameLength);
+		  if (!RtlEqualUnicodePathSuffix (&upath, &npath, !!ci_flag))
+		    {
+		      fileattr = INVALID_FILE_ATTRIBUTES;
+		      set_error (ENOENT);
+		      break;
+		    }
+		}
+	    }
 	}
       if (!NT_SUCCESS (status))
 	{


                 reply	other threads:[~2021-04-19 12:55 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=20210419125500.402EE386FC2B@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).