From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A4C4A1F5AE for ; Mon, 3 May 2021 19:26:37 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CFDE393C846; Mon, 3 May 2021 19:26:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CFDE393C846 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620069996; bh=Lb5U3uG3DEBNwU+J/ItOv/5fLpumnsnqaOpiZ7gR+vM=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iL8FkkkQzdvUAGN6q9NSswW9QY6328AS+R6xA9Y5uUErOXUkbxs7KJevIteL/WRfV Ugs25y4Dl4uzHZZA9sIzloNHw11LeM/JTAGXPMPy8poMRZosS8RDaWBndkY3p9OeYo Q5WaGoXVrajUxyQ/QLHrM6trY54L0sB9+/de9dF4= Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by sourceware.org (Postfix) with ESMTPS id CCE773857000 for ; Mon, 3 May 2021 19:26:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CCE773857000 Received: by mail-qv1-xf34.google.com with SMTP id q5so3206051qvv.6 for ; Mon, 03 May 2021 12:26:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Lb5U3uG3DEBNwU+J/ItOv/5fLpumnsnqaOpiZ7gR+vM=; b=TkdczoqfVLQKjr6zNmzrs1lZFozb0R/PqrnXMHahL6ONMTjQtgLrr1/Nao/BMh/Qo9 kFNIiTHwA6muYW1Nrm26yH7FOgPEuzi6WArsz0W7tuAELuwNjWWt/Kj7lXJDS/lBGRar lGgYsLzCD3qw92pRm/kYgkRj/EDtjRey1GAB/oLhiAFR6V70wT6EP6sMhdx75vAd9EwK SuuhBpSiweCy3ATaH15JfNYVFwa8sfD1XexGe6Uk/CPzwgmvm33/G9xD+u2h+Ao0FKrY dRHivH4fe6c9ov1TqOa2MI0c3jYSFF12kwhyquVHVKci8uFsU6O+IY1MH/ih2TESEr0W VsYA== X-Gm-Message-State: AOAM533TZ1eFG7WWth/X3zndTjx8MMC9avI8Qcu9HnX7rdCQYolg/JNR mT1UAWMQa5WD5TeFLCFNtzeynvrBPhgpWQ== X-Google-Smtp-Source: ABdhPJx6iJCPchZxEQ5S7cLr2sjKxID31cR0yrcGvOMVz3Mjxs4bpFr54Rt5gpgkr0298P/6Qs61rA== X-Received: by 2002:ad4:48c4:: with SMTP id v4mr11728780qvx.16.1620069993171; Mon, 03 May 2021 12:26:33 -0700 (PDT) Received: from [192.168.1.4] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id c187sm9160061qkd.8.2021.05.03.12.26.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 May 2021 12:26:32 -0700 (PDT) Subject: Re: [RFC v2] linux: use __fd_to_filename helper function instead of snprintf. To: =?UTF-8?Q?=c3=89rico_Nogueira?= , libc-alpha@sourceware.org References: <20210427130945.917-1-ericonr@disroot.org> Message-ID: Date: Mon, 3 May 2021 16:26:30 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210427130945.917-1-ericonr@disroot.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On 27/04/2021 10:09, Érico Nogueira via Libc-alpha wrote: > Change made to fchmodat and fexecve. There are tests using xasprintf > instead of this helper as well, but this commit doesn't touch them. To adapt the tests it would require either to build it as internal/static or add fd_to_filename to libsupport. I am not this is really an improvement. LGTM, thanks. I will commit this for you. 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; > >