diff options
author | Bruno Haible <bruno@clisp.org> | 2020-03-07 19:56:33 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-03-07 19:56:33 +0100 |
commit | 4c1009ec93e12ee34acd27f6d7e25442bedc16f2 (patch) | |
tree | 5d0a81a0651886ef97e7535dbb6ec2bda7ed2940 /lib/progreloc.c | |
parent | a99ca2e041127e0c0d6c14273097c86879a6ebe3 (diff) | |
download | gnulib-4c1009ec93e12ee34acd27f6d7e25442bedc16f2.tar.gz |
findprog, relocatable-prog: Ignore directories during PATH search.
Reported by Frederick Eaton via Dmitry Goncharov in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-03/msg00003.html>.
* 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.
Diffstat (limited to 'lib/progreloc.c')
-rw-r--r-- | lib/progreloc.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/progreloc.c b/lib/progreloc.c index 2acf3fb33f..04cef323f3 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 pathname may belong to the executable. */ +/* Tests whether a given filename may belong to the executable. */ static bool maybe_executable (const char *filename) { @@ -173,18 +173,20 @@ maybe_executable (const char *filename) struct stat statfile; if (fstat (executable_fd, &statexe) >= 0) - { - if (stat (filename, &statfile) < 0) - return false; - if (!(statfile.st_dev + return (stat (filename, &statfile) >= 0 + && statfile.st_dev && statfile.st_dev == statexe.st_dev - && statfile.st_ino == statexe.st_ino)) - return false; - } + && statfile.st_ino == statexe.st_ino); } # endif - return true; + /* Check that the filename does not point to a directory. */ + { + struct stat statfile; + + return (stat (filename, &statfile) >= 0 + && ! S_ISDIR (statfile.st_mode)); + } } #endif |