From patchwork Tue Apr 27 13:09:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C3=89rico_Nogueira?= X-Patchwork-Id: 43165 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com 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 76BA0398B400; Tue, 27 Apr 2021 13:09:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76BA0398B400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1619528997; bh=qKlceQE7Co+NNJdSGs1zUyIdHYzfsn5B8ZnS0dRfYys=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=SNrLVwB2RXZv5Tmn9jonX81hqKlKQxyo0rZUjPUySDFPDFS8xI1IPEmpPssv1IdtZ geuu1Mil/t65EOIbR8rpDDoCeEemskRcrj355BLeaV4dAJ2l7lCEZwDIrA4LXmZktI 21uR7/YfjtBgXH2jVHISReoiYzkeb7r5X6Tqr7tk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id D3B04398B400 for ; Tue, 27 Apr 2021 13:09:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D3B04398B400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id F41C253014; Tue, 27 Apr 2021 15:09:52 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9uYXIhxsEFAK; Tue, 27 Apr 2021 15:09:51 +0200 (CEST) To: libc-alpha@sourceware.org Subject: [RFC v2] linux: use __fd_to_filename helper function instead of snprintf. Date: Tue, 27 Apr 2021 10:09:45 -0300 Message-Id: <20210427130945.917-1-ericonr@disroot.org> Mime-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , X-Patchwork-Original-From: =?utf-8?q?=C3=89rico_Nogueira_via_Libc-alpha?= From: =?utf-8?q?=C3=89rico_Nogueira?= Reply-To: =?utf-8?q?=C3=89rico_Nogueira?= Cc: =?utf-8?q?=C3=89rico_Nogueira?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Change made to fchmodat and fexecve. There are tests using xasprintf instead of this helper as well, but this commit doesn't touch them. Reviewed-by: Adhemerval Zanella --- Differences from v1: - actually builds - doesn't use an intermediary buf variable sysdeps/unix/sysv/linux/fchmodat.c | 13 +++---------- sysdeps/unix/sysv/linux/fexecve.c | 10 ++++------ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/sysdeps/unix/sysv/linux/fchmodat.c b/sysdeps/unix/sysv/linux/fchmodat.c index f264f0c09d..5bd1eb96a5 100644 --- a/sysdeps/unix/sysv/linux/fchmodat.c +++ b/sysdeps/unix/sysv/linux/fchmodat.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -69,16 +70,8 @@ fchmodat (int fd, const char *file, mode_t mode, int flag) /* For most file systems, fchmod does not operate on O_PATH descriptors, so go through /proc. */ - char buf[32]; - if (__snprintf (buf, sizeof (buf), "/proc/self/fd/%d", pathfd) < 0) - { - /* This also may report strange error codes to the caller - (although snprintf really should not fail). */ - __close_nocancel (pathfd); - return -1; - } - - int ret = __chmod (buf, mode); + struct fd_to_filename filename; + int ret = __chmod (__fd_to_filename (pathfd, &filename), mode); if (ret != 0) { if (errno == ENOENT) diff --git a/sysdeps/unix/sysv/linux/fexecve.c b/sysdeps/unix/sysv/linux/fexecve.c index f37c245396..df25c2acb8 100644 --- a/sysdeps/unix/sysv/linux/fexecve.c +++ b/sysdeps/unix/sysv/linux/fexecve.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -49,12 +50,9 @@ fexecve (int fd, char *const argv[], char *const envp[]) #ifndef __ASSUME_EXECVEAT /* We use the /proc filesystem to get the information. If it is not - mounted we fail. */ - char buf[sizeof "/proc/self/fd/" + sizeof (int) * 3]; - __snprintf (buf, sizeof (buf), "/proc/self/fd/%d", fd); - - /* We do not need the return value. */ - __execve (buf, argv, envp); + mounted we fail. We do not need the return value. */ + struct fd_to_filename filename; + __execve (__fd_to_filename (fd, &filename), argv, envp); int save = errno;