From 394cea93e936283ae22a37f8d4a2782cb6ae09bb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 26 Sep 2024 08:06:10 -0700 Subject: [PATCH 2/2] =?UTF-8?q?[maint]=20Stop=20using=20=E2=80=98access?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s wrong for setuid scripts, and using faccessat would drag in more Gnulib code. Simply use ‘open’ to test readability. * super.c: Include , for ‘open’. (access_file_for_read): New function. (main): Use it instead of ‘access’. --- src/ChangeLog | 6 ++++++ src/super.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index bab662a..dc6375c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2024-09-26 Paul Eggert + [maint] Stop using ‘access’ + It’s wrong for setuid scripts, and using faccessat would + drag in more Gnulib code. Simply use ‘open’ to test readability. + * super.c (access_file_for_read): New function. + (main): Use it instead of ‘access’. + [maint] Stop using findprog * b-peer.c: Do not include findprog.h. (EXEEXT): Default to empty. diff --git a/src/super.c b/src/super.c index 685e6bb..673390a 100644 --- a/src/super.c +++ b/src/super.c @@ -20,6 +20,7 @@ */ #include "base.h" +#include #include #include #include @@ -224,6 +225,14 @@ huh (const char *what, const char *argv1) #define HUH(what) huh (what, argv[1]) +static int +access_file_for_read (char const *name) +{ + /* Do not use 'faccessat' as that would drag in more Gnulib modules. */ + int fd = open (name, O_RDONLY | OPEN_O_BINARY); + return fd < 0 ? fd : close (fd); +} + DECLARE_PROGRAM (super, TYAG_IMMEDIATE); int @@ -307,7 +316,7 @@ main (int argc, char *argv[VLA_ELEMS (argc)]) TODO: Move "usage is obsolescent" handling from rcs.c to here, zonk the heuristic, and be happy (maybe). */ else if (strchr (cmd, SLASH) - || ! PROB (access (cmd, R_OK))) + || ! PROB (access_file_for_read (cmd))) goto legacy; /* No luck, sorry. */ -- 2.43.0