From patchwork Sun Jan 19 14:12:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 105057 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05CC53858C31 for ; Sun, 19 Jan 2025 14:12:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05CC53858C31 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 2A0403858D38 for ; Sun, 19 Jan 2025 14:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A0403858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2A0403858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.77.166.138 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737295930; cv=none; b=AReIhswhiEryV2vdzEPMymiCAeqY8Tp4L4sgR2D/QPxv6OuEinHV349HGG6c78317UYVaAatFuRLg6dXZ49TZr91dBU5HbOfvV35HXQ2pUYeEH3oOCVIxGlMYTDcBTNzgjxfeM7hrr7RhLEK7+j6zYCFyiiyfpDa6iHfOeNkMLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737295930; c=relaxed/simple; bh=x8FVrVNzYBztRUlkBQVxu9t3ANYGhbtsBt55mhLeydg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=mR+RvKmku43k6re0NJ9gztHRQP5BMHamP4avFiBVb3Z7CYHiFCjRXFkD1I2JwoILXJHcv2b6xws82/IZAUq8kJ4A/jkjGTtqVFosp2cNgA7a2Yorkb8GnoswvlhyqhYjOVOfm+DKgBRLrOZ2OhwhsZj0LkHfXAAq7Sos/LY4/C8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A0403858D38 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 8B26FA1A1B; Sun, 19 Jan 2025 15:12:07 +0100 (CET) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ytDIBBjemkpy; Sun, 19 Jan 2025 15:12:07 +0100 (CET) Received: from begin (aamiens-653-1-40-48.w83-192.abo.wanadoo.fr [83.192.199.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 6A91EA19D6; Sun, 19 Jan 2025 15:12:07 +0100 (CET) Received: from samy by begin with local (Exim 4.98) (envelope-from ) id 1tZW22-00000005xKy-3zln; Sun, 19 Jan 2025 15:12:06 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd, commited] hurd: Fix EINVAL error on linking to a slash-trailing path [BZ #32569] Date: Sun, 19 Jan 2025 15:12:06 +0100 Message-ID: <20250119141206.1419725-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org When the target path finishes with a slash, __file_name_split_at returns an empty file name. We can test for this to refuse doing the link. --- sysdeps/mach/hurd/bind.c | 8 ++++++-- sysdeps/mach/hurd/linkat.c | 6 +++++- sysdeps/mach/hurd/mknodat.c | 8 ++++++-- sysdeps/mach/hurd/symlinkat.c | 8 ++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/sysdeps/mach/hurd/bind.c b/sysdeps/mach/hurd/bind.c index f4cf5bd14e..bb408afcf6 100644 --- a/sysdeps/mach/hurd/bind.c +++ b/sysdeps/mach/hurd/bind.c @@ -47,8 +47,12 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len) if (dir == MACH_PORT_NULL) return -1; - /* Create a new, unlinked node in the target directory. */ - err = __dir_mkfile (dir, O_CREAT, 0666 & ~_hurd_umask, &node); + if (! *n) + /* Can't bind on the existing directory itself. */ + err = ENOTDIR; + else + /* Create a new, unlinked node in the target directory. */ + err = __dir_mkfile (dir, O_CREAT, 0666 & ~_hurd_umask, &node); if (! err) { diff --git a/sysdeps/mach/hurd/linkat.c b/sysdeps/mach/hurd/linkat.c index 75b4244f57..8f8e6c36fb 100644 --- a/sysdeps/mach/hurd/linkat.c +++ b/sysdeps/mach/hurd/linkat.c @@ -48,7 +48,11 @@ __linkat_common (int fromfd, const char *from, int tofd, const char *to, int at_ todir = __file_name_split_at (tofd, to, &toname); if (todir != MACH_PORT_NULL) { - err = __dir_link (todir, linknode, toname, 1); + if (! *toname) + /* Can't link to the existing directory itself. */ + err = ENOTDIR; + else + err = __dir_link (todir, linknode, toname, 1); __mach_port_deallocate (__mach_task_self (), todir); } __mach_port_deallocate (__mach_task_self (), linknode); diff --git a/sysdeps/mach/hurd/mknodat.c b/sysdeps/mach/hurd/mknodat.c index 13f2191766..c1fe3430d0 100644 --- a/sysdeps/mach/hurd/mknodat.c +++ b/sysdeps/mach/hurd/mknodat.c @@ -88,8 +88,12 @@ __mknodat (int fd, const char *path, mode_t mode, dev_t dev) if (dir == MACH_PORT_NULL) return -1; - /* Create a new, unlinked node in the target directory. */ - errnode = err = __dir_mkfile (dir, O_WRITE, (mode & ~S_IFMT) & ~_hurd_umask, &node); + if (! *name) + /* Can't link to the existing directory itself. */ + errnode = err = ENOTDIR; + else + /* Create a new, unlinked node in the target directory. */ + errnode = err = __dir_mkfile (dir, O_WRITE, (mode & ~S_IFMT) & ~_hurd_umask, &node); if (! err && translator != NULL) /* Set the node's translator to make it a device. */ diff --git a/sysdeps/mach/hurd/symlinkat.c b/sysdeps/mach/hurd/symlinkat.c index 8f72b2bea2..e7dfb673df 100644 --- a/sysdeps/mach/hurd/symlinkat.c +++ b/sysdeps/mach/hurd/symlinkat.c @@ -45,8 +45,12 @@ __symlinkat (const char *from, int fd, const char *to) if (dir == MACH_PORT_NULL) return -1; - /* Create a new, unlinked node in the target directory. */ - err = __dir_mkfile (dir, O_WRITE, 0777 & ~_hurd_umask, &node); + if (! *name) + /* Can't link to the existing directory itself. */ + err = ENOTDIR; + else + /* Create a new, unlinked node in the target directory. */ + err = __dir_mkfile (dir, O_WRITE, 0777 & ~_hurd_umask, &node); if (! err) {