From patchwork Sun Mar 18 19:44:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 26365 Received: (qmail 343 invoked by alias); 18 Mar 2018 19:45:00 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 307 invoked by uid 89); 18 Mar 2018 19:44:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=H*r:sk:static-, H*RU:sk:static-, Hx-spam-relays-external:sk:static- X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault Subject: [hurd,commited 2/5] hurd: Fix O_DIRECTORY | O_NOFOLLOW Date: Sun, 18 Mar 2018 20:44:48 +0100 Message-Id: <20180318194451.11862-3-samuel.thibault@ens-lyon.org> In-Reply-To: <20180318194451.11862-1-samuel.thibault@ens-lyon.org> References: <20180318194451.11862-1-samuel.thibault@ens-lyon.org> Appending / to the path to be looked up would make us always follow a final symlink, even with O_NOTRANS (since the final resolution is after the '/'). In the O_DIRECTORY | O_NOFOLLOW case, we thus have to really open the node and stat it, which we already do anyway, and check for directory type. * hurd/hurdlookup.c (__hurd_file_name_lookup): Do not append '/' to path when flags contains O_NOFOLLOW. * hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ENOTDIR if flags contains O_DIRECTORY and the result is a directory. --- ChangeLog | 4 ++++ hurd/hurdlookup.c | 2 +- hurd/lookup-retry.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 82ddda54ba..a02f9017de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -64,6 +64,10 @@ * sysdeps/mach/hurd/cthreads.c: Include . * hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ELOOP when opening a symlink with O_NOFOLLOW. + * hurd/hurdlookup.c (__hurd_file_name_lookup): Do not append '/' to + path when flags contains O_NOFOLLOW. + * hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ENOTDIR + if flags contains O_DIRECTORY and the result is a directory. 2018-03-17 Samuel Thibault diff --git a/hurd/hurdlookup.c b/hurd/hurdlookup.c index 1861d5879d..a642c49002 100644 --- a/hurd/hurdlookup.c +++ b/hurd/hurdlookup.c @@ -72,7 +72,7 @@ __hurd_file_name_lookup (error_t (*use_init_port) if (flags & O_NOFOLLOW) /* See lookup-retry.c about O_NOFOLLOW. */ flags |= O_NOTRANS; - if (flags & O_DIRECTORY) + if (flags & O_DIRECTORY && (flags & O_NOFOLLOW) == 0) { /* The caller wants to require that the file we look up is a directory. We can do this without an extra RPC by appending a trailing slash diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c index 12b5c30962..b596848624 100644 --- a/hurd/lookup-retry.c +++ b/hurd/lookup-retry.c @@ -147,6 +147,8 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) err = __io_stat (*result, &st); if (!err) { + if (flags & O_DIRECTORY && !S_ISDIR (st.st_mode)) + err = ENOTDIR; if (S_ISLNK (st.st_mode)) err = ELOOP; else if (st.st_mode & (S_IPTRANS|S_IATRANS))