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: POSIX ipc: fix evaluation of naming rules Date: Fri, 21 May 2021 13:34:27 +0000 (GMT) [thread overview] Message-ID: <20210521133427.E9DC7384781C@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=5b380b1ca671a595a06edbe9cdc630def94cdb49 commit 5b380b1ca671a595a06edbe9cdc630def94cdb49 Author: Corinna Vinschen <corinna@vinschen.de> Date: Fri May 21 15:21:29 2021 +0200 Cygwin: POSIX ipc: fix evaluation of naming rules The function evaluating correctness of ipc object names was a bit half-hearted. Fix the tests to follow more closely the desriptions in the Linux man pages. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/posix_ipc.cc | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/winsup/cygwin/posix_ipc.cc b/winsup/cygwin/posix_ipc.cc index 11d5b4058..7038d1146 100644 --- a/winsup/cygwin/posix_ipc.cc +++ b/winsup/cygwin/posix_ipc.cc @@ -67,22 +67,33 @@ check_path (char *res_name, ipc_type_t type, const char *name, size_t len) set_errno (EINVAL); return false; } - /* Name must not be empty, or just be a single slash, or start with more - than one slash. Same for backslash. - Apart from handling backslash like slash, the naming rules are identical + /* Apart from handling backslash like slash, the naming rules are identical to Linux, including the names and requirements for subdirectories, if the name contains further slashes. */ - if (!name || (strchr ("/\\", name[0]) - && (!name[1] || strchr ("/\\", name[1])))) + /* Name must not be empty and has to start with a slash (or backslash) */ + if (!name || !strchr ("/\\", name[0])) { debug_printf ("Invalid %s name '%s'", ipc_names[type].description, name); set_errno (EINVAL); return false; } - /* Skip leading (back-)slash. */ - if (strchr ("/\\", name[0])) - ++name; - if (len > PATH_MAX - ipc_names[type].prefix_len) + /* Name must not consist of just a single slash (or backslash) */ + if (!name[1]) + { + debug_printf ("Invalid %s name '%s'", ipc_names[type].description, name); + set_errno (ENOENT); + return false; + } + /* Name must not contain slashes after the leading one */ + if (strpbrk (name + 1, "/\\")) + { + debug_printf ("Invalid %s name '%s'", ipc_names[type].description, name); + set_errno (EACCES); + return false; + } + /* Length must be less than or equal to NAME_MAX, or NAME_MAX - 4 in + case of semaphores, due to the leading "sem." prefix */ + if (len > NAME_MAX - (type == semaphore ? strlen ("sem.") : 0)) { debug_printf ("%s name '%s' too long", ipc_names[type].description, name); set_errno (ENAMETOOLONG); @@ -90,7 +101,7 @@ check_path (char *res_name, ipc_type_t type, const char *name, size_t len) } __small_sprintf (res_name, "%s/%s%s", ipc_names[type].prefix, type == semaphore ? "sem." : "", - name); + name + 1); return true; }
reply other threads:[~2021-05-21 13:34 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=20210521133427.E9DC7384781C@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: linkBe 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).