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/main] Cygwin: mount: differ allowed server name chars from allowed share name chars
Date: Mon, 23 Jan 2023 13:17:02 +0000 (GMT)	[thread overview]
Message-ID: <20230123131702.33D553858D33@sourceware.org> (raw)

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

commit cad3913ed8b1ce5db9396edc2f9e461cdb10998b
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Mon Jan 23 14:01:43 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Mon Jan 23 14:02:20 2023 +0100

    Cygwin: mount: differ allowed server name chars from allowed share name chars
    
    The list of invalid chars for server names differs from the
    list of invalid chars for share names.  Apart from that,
    we don't allow control chars in both kinds of names.
    
    Fixes: 6338d2f24a60 ("Cygwin: mount: allow any valid character in UNC paths")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/mount.cc | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc
index d8e6e043b8d4..b44d60e1e3eb 100644
--- a/winsup/cygwin/mount.cc
+++ b/winsup/cygwin/mount.cc
@@ -51,10 +51,23 @@ int NO_COPY mount_info::root_idx = -1;
    This function is only used to test for valid input strings.
    The later normalization drops the native prefixes. */
 
+/* list of invalid chars in server names.  Note that underscore is ok,
+   but it cripples interoperability. */
+const char _invalid_server_char[] = ",~:!@#$%^&'.(){} ";
+#define valid_server_char(_c)	({				\
+		const char __c = (_c);				\
+		!iscntrl(__c)					\
+		&& strchr (_invalid_server_char, (_c)) == NULL;	\
+	})
+
 /* list of invalid chars in UNC filenames.  These are a few more than
    for "normal" filenames. */
-const char _invalid_char[] = "\"/\\[]:|<>+=;,?*";
-#define valid_share_char(_c)	(strchr (_invalid_char, (_c)) == NULL)
+const char _invalid_share_char[] = "\"/\\[]:|<>+=;,?*";
+#define valid_share_char(_c)	({				\
+		const char __c = (_c);				\
+		!iscntrl(__c)					\
+		&& strchr (_invalid_share_char, __c) == NULL;	\
+	})
 
 static inline bool
 is_native_path (const char *path)
@@ -72,7 +85,7 @@ is_unc_share (const char *path)
   const char *p;
   return (isdirsep (path[0])
 	 && isdirsep (path[1])
-	 && valid_share_char (path[2])
+	 && valid_server_char (path[2])
 	 && ((p = strpbrk (path + 3, "\\/")) != NULL)
 	 && valid_share_char (p[1]));
 }

                 reply	other threads:[~2023-01-23 13:17 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=20230123131702.33D553858D33@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).