From patchwork Fri Oct 16 10:09:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Li X-Patchwork-Id: 40738 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 3F7E63953CE6; Fri, 16 Oct 2020 10:11:37 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from vipregular1.263.net (vipregular1.263.net [211.150.80.21]) by sourceware.org (Postfix) with ESMTPS id 481373857817 for ; Fri, 16 Oct 2020 10:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 481373857817 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=uniontech.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=chenli@uniontech.com Received: from localhost (unknown [192.168.167.8]) by vipregular1.263.net (Postfix) with ESMTP id 974EC2F1 for ; Fri, 16 Oct 2020 18:11:26 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 Received: from manjaro.uniontech.com (unknown [58.246.122.242]) by smtp.263.net (postfix) whith ESMTP id P2454T140206485231360S1602843086045065_; Fri, 16 Oct 2020 18:11:26 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <1730ec5195ee4172272d2e969afcec2a> X-RL-SENDER: chenli@uniontech.com X-SENDER: chenli@uniontech.com X-LOGIN-NAME: chenli@uniontech.com X-FST-TO: libc-alpha@sourceware.org X-SENDER-IP: 58.246.122.242 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 Date: Fri, 16 Oct 2020 18:09:58 +0800 Message-ID: <87lfg6zdl5.wl-chenli@uniontech.com> From: Chen Li To: libc-alpha@sourceware.org Subject: [PATCH] shm_open/unlink: fix errno if namelen >= NAME_MAX User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?iso-8859-4?q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, LONGWORDS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" According to linux's manpage and posix's doc, errno should be set to ENAMETOOLONG if the path exceeds the maximuz length: linux man page(http://man7.org/linux/man-pages/man3/shm_open.3.html) ``` ENAMETOOLONG The length of name exceeds PATH_MAX. ``` posix doc(https://pubs.opengroup.org/onlinepubs/009695399/functions/shm_open.html): ``` [ENAMETOOLONG] The length of the name argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}. ``` glibc doesn't handle ENAMETOOLONG correctly previously. When the path exceeds the maximum value, errno was set to EINVAL instead, which doesn't conform the man page and posix standard. This patch removes the NAME_MAX check in SHM_GET_NAME and leaves this check to open syscall, which should handle maximunize length correctly inside various filesystem implementations. --- sysdeps/posix/shm-directory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/posix/shm-directory.h b/sysdeps/posix/shm-directory.h index c7979ebb72..5a1aab2c14 100644 --- a/sysdeps/posix/shm-directory.h +++ b/sysdeps/posix/shm-directory.h @@ -53,7 +53,7 @@ extern const char *__shm_directory (size_t *len); ++name; \ size_t namelen = strlen (name) + 1; \ /* Validate the filename. */ \ - if (namelen == 1 || namelen >= NAME_MAX || strchr (name, '/') != NULL) \ + if (namelen == 1 || strchr (name, '/') != NULL) \ { \ __set_errno (errno_for_invalid); \ return retval_for_invalid; \