From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id EFEEB39540F0; Mon, 3 May 2021 19:46:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFEEB39540F0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc] linux: use __fd_to_filename helper function instead of snprintf. X-Act-Checkin: glibc X-Git-Author: =?utf-8?q?=C3=89rico_Nogueira?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 19d83270fcd993cc349570164e21b06d57036704 X-Git-Newrev: 77c1573dbceebf75203e4201615def9765599d87 Message-Id: <20210503194638.EFEEB39540F0@sourceware.org> Date: Mon, 3 May 2021 19:46:38 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 May 2021 19:46:39 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=77c1573dbceebf75203e4201615def9765599d87 commit 77c1573dbceebf75203e4201615def9765599d87 Author: Érico Nogueira Date: Tue Apr 27 10:09:45 2021 -0300 linux: use __fd_to_filename helper function instead of snprintf. Change made to fchmodat and fexecve. There are tests using xasprintf instead of this helper as well, but this commit doesn't touch them. Diff: --- 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;