]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: mount: differ allowed server name chars from allowed share name chars
authorCorinna Vinschen <corinna@vinschen.de>
Mon, 23 Jan 2023 13:01:43 +0000 (14:01 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Mon, 23 Jan 2023 13:03:25 +0000 (14:03 +0100)
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>
winsup/cygwin/mount.cc

index 61e4c5d33347aede7e00e8e635678ad762756a56..14c1ac729437f711927e8be6b4accf41a1d5b11a 100644 (file)
@@ -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]));
 }
This page took 0.03689 seconds and 5 git commands to generate.