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: introduce isabspath_strict macro
Date: Thu, 11 Nov 2021 10:03:36 +0000 (GMT)	[thread overview]
Message-ID: <20211111100336.DFDDC3858037@sourceware.org> (raw)

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

commit 7e7d471644914397ca1e86ee99b6fc85160280c8
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Nov 10 21:17:30 2021 +0100

    Cygwin: introduce isabspath_strict macro
    
    isabspath handles a path "X:", without trailing slash or backslash,
    as absolute path.  This breaks some scenarios with relative paths
    starting with "X:".  For instance, fstatat will mishandle a call
    with valid dirfd and "c:" as path.
    
    The reason is that gen_full_path_at() will check for isabspath("C:")
    which returns true.  So the path will be used verbatim in fstatat,
    rather than being converted to a path "<dirfd-path>/c:".
    
    So, introduce isabspath_strict, which returns true for paths starting
    with "X:" only if the next char is actually a slash or backslash.
    Use it from gen_full_path_at().
    
    This still fixes only half the problem.  The right thing would have been
    to disallow using DOS paths in the first place.  Unfortunately it's much
    too late for that.
    
    Addresses: https://cygwin.com/pipermail/cygwin/2021-November/249837.html
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/syscalls.cc | 2 +-
 winsup/cygwin/winsup.h    | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 7a48e422e..661c14347 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -4714,7 +4714,7 @@ gen_full_path_at (char *path_ret, int dirfd, const char *pathname,
 	  return -1;
 	}
     }
-  if (pathname && isabspath (pathname))
+  if (pathname && isabspath_strict (pathname))
     stpcpy (path_ret, pathname);
   else
     {
diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h
index f6fea6313..1f265ec28 100644
--- a/winsup/cygwin/winsup.h
+++ b/winsup/cygwin/winsup.h
@@ -139,9 +139,17 @@ extern int cygserver_running;
 #undef issep
 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
 
+/* Treats "X:" as absolute path.
+   FIXME: We should drop the notion that "X:" is a valid absolute path.
+   Only "X:/" and "X:\\" should be (see isabspath_strict below).  The
+   problem is to find out if we have code depending on this behaviour. */
 #define isabspath(p) \
   (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
 
+/* Treats "X:/" and "X:\\" as absolute paths, but not "X:" */
+#define isabspath_strict(p) \
+  (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && isdirsep ((p)[2])))
+
 /******************** Initialization/Termination **********************/
 
 class per_process;


                 reply	other threads:[~2021-11-11 10:03 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=20211111100336.DFDDC3858037@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).