From 36ebd778f6c9c35c8a8d25d81a893b6e5a4fdf9d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 7 Mar 2020 20:44:47 +0100 Subject: [PATCH] Revert my last commit, due to compilation errors. --- ChangeLog | 9 --------- lib/findprog.c | 35 ++++++++++++++--------------------- lib/progreloc.c | 20 +++++++++----------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6bd5180ca..d36c58b98a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,15 +7,6 @@ * lib/openat.c (rpl_openat): Don’t assume O_RDONLY is disjoint from O_RDWR. -2020-03-07 Bruno Haible - - findprog, relocatable-prog: Ignore directories during PATH search. - Reported by Frederick Eaton via Dmitry Goncharov in - . - * lib/findprog.c (find_in_path): When the file found in a PATH element - is a directory, continue searching. - * lib/progreloc.c (maybe_executable): Likewise. - 2020-03-07 Bruno Haible openat: Fix theoretically possible issue on GNU/Hurd. diff --git a/lib/findprog.c b/lib/findprog.c index d834301bd7..d0d41791e2 100644 --- a/lib/findprog.c +++ b/lib/findprog.c @@ -105,29 +105,22 @@ find_in_path (const char *progname) design flaw. */ if (eaccess (progpathname, X_OK) == 0) { - /* Check that the progpathname does not point to a directory. */ - struct stat statbuf; - - if (stat (progpathname, &statbuf) >= 0 - && ! S_ISDIR (statbuf.st_mode)) + /* Found! */ + if (strcmp (progpathname, progname) == 0) { - /* Found! */ - if (strcmp (progpathname, progname) == 0) - { - free (progpathname); - - /* Add the "./" prefix for real, that xconcatenated_filename() - optimized away. This avoids a second PATH search when the - caller uses execlp/execvp. */ - progpathname = XNMALLOC (2 + strlen (progname) + 1, char); - progpathname[0] = '.'; - progpathname[1] = '/'; - memcpy (progpathname + 2, progname, strlen (progname) + 1); - } - - free (path); - return progpathname; + free (progpathname); + + /* Add the "./" prefix for real, that xconcatenated_filename() + optimized away. This avoids a second PATH search when the + caller uses execlp/execvp. */ + progpathname = XNMALLOC (2 + strlen (progname) + 1, char); + progpathname[0] = '.'; + progpathname[1] = '/'; + memcpy (progpathname + 2, progname, strlen (progname) + 1); } + + free (path); + return progpathname; } free (progpathname); diff --git a/lib/progreloc.c b/lib/progreloc.c index 04cef323f3..2acf3fb33f 100644 --- a/lib/progreloc.c +++ b/lib/progreloc.c @@ -154,7 +154,7 @@ static int executable_fd = -1; /* Define this function only when it's needed. */ #if !(defined WINDOWS_NATIVE || defined __EMX__) -/* Tests whether a given filename may belong to the executable. */ +/* Tests whether a given pathname may belong to the executable. */ static bool maybe_executable (const char *filename) { @@ -173,20 +173,18 @@ maybe_executable (const char *filename) struct stat statfile; if (fstat (executable_fd, &statexe) >= 0) - return (stat (filename, &statfile) >= 0 - && statfile.st_dev + { + if (stat (filename, &statfile) < 0) + return false; + if (!(statfile.st_dev && statfile.st_dev == statexe.st_dev - && statfile.st_ino == statexe.st_ino); + && statfile.st_ino == statexe.st_ino)) + return false; + } } # endif - /* Check that the filename does not point to a directory. */ - { - struct stat statfile; - - return (stat (filename, &statfile) >= 0 - && ! S_ISDIR (statfile.st_mode)); - } + return true; } #endif -- 2.39.5