From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id A47B43858D32; Sun, 22 Jan 2023 19:16:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A47B43858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674414995; bh=jV8nidjCXizhEzGFcglAJEh77Lyqz84Km0sfkAkPDXk=; h=From:To:Subject:Date:From; b=Qtm+wDCAlh0SEEtW//M//ntP2oVwM9aX12HRaxwVzqvIegkSkn0irvdfoqAnSbhQz oLEnEfOayW/xFzFvN4KtC8YyGWvSiGPSrgCKIG5qFU0UrsBG2+Vou04L/wQmRw/2US WjyzQ7wv8R9teCSB0Nl1hYPDLw1EnCHQx4+zBcjw= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: mount: allow any valid character in UNC paths X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: 17ad18afc62ceefe01273e4c2fff9114275ab909 X-Git-Newrev: 33e4340d44a8a316d548de6344ee6d1aa6c5fb7f Message-Id: <20230122191635.A47B43858D32@sourceware.org> Date: Sun, 22 Jan 2023 19:16:35 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D33e4340d44a= 8a316d548de6344ee6d1aa6c5fb7f commit 33e4340d44a8a316d548de6344ee6d1aa6c5fb7f Author: Corinna Vinschen AuthorDate: Sun Jan 22 20:11:59 2023 +0100 Commit: Corinna Vinschen CommitDate: Sun Jan 22 20:16:13 2023 +0100 Cygwin: mount: allow any valid character in UNC paths =20 The current code only allows server and share names to start with ASCII chars [a-zA-Z0-9],, which is not correct. Rather, check for a valid share character. =20 Fixes: 1fd5e000ace55 ("import winsup-2000-02-17 snapshot") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/mount.cc | 15 ++++++++++++--- winsup/cygwin/release/3.4.6 | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc index 63c9d2874121..61e4c5d33347 100644 --- a/winsup/cygwin/mount.cc +++ b/winsup/cygwin/mount.cc @@ -42,11 +42,20 @@ bool NO_COPY mount_info::got_usr_bin; bool NO_COPY mount_info::got_usr_lib; int NO_COPY mount_info::root_idx =3D -1; =20 -/* is_unc_share: Return non-zero if PATH begins with //server/share +/* is_native_path: Return non-zero if PATH starts with \??\[a-zA-Z] or + with \\?\[a-zA-Z] or with \\.\[a-zA-Z]. + + is_unc_share: Return non-zero if PATH begins with //server/share or with one of the native prefixes //./ or //?/ + This function is only used to test for valid input strings. The later normalization drops the native prefixes. */ =20 +/* list of invalid chars in UNC filenames. These are a few more than + for "normal" filenames. */ +const char _invalid_char[] =3D "\"/\\[]:|<>+=3D;,?*"; +#define valid_share_char(_c) (strchr (_invalid_char, (_c)) =3D=3D NULL) + static inline bool is_native_path (const char *path) { @@ -63,9 +72,9 @@ is_unc_share (const char *path) const char *p; return (isdirsep (path[0]) && isdirsep (path[1]) - && isalnum (path[2]) + && valid_share_char (path[2]) && ((p =3D strpbrk (path + 3, "\\/")) !=3D NULL) - && isalnum (p[1])); + && valid_share_char (p[1])); } =20 /* Return true if src_path is a valid, internally supported device name. diff --git a/winsup/cygwin/release/3.4.6 b/winsup/cygwin/release/3.4.6 index c1476ff4602b..c21c44fbf55a 100644 --- a/winsup/cygwin/release/3.4.6 +++ b/winsup/cygwin/release/3.4.6 @@ -3,3 +3,6 @@ Bug Fixes =20 Fix a problem that fsync returns EINVAL for block device. Addresses: https://cygwin.com/pipermail/cygwin/2023-January/252916.html + +Don't reject valid server and share names when mounting. +Addresses: https://cygwin.com/pipermail/cygwin/2023-January/252928.html