+2020-04-10 Bruno Haible <bruno@clisp.org>
+
+ 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.
+ * modules/findprog (Depends-on): Add sys_stat, stat.
+ * modules/findprog-lgpl (Depends-on): Likewise.
+
+ * lib/progreloc.c (maybe_executable): When the file found in a PATH
+ element is a directory, continue searching.
+ * lib/relocwrapper.c: Update comments.
+ * modules/relocatable-prog-wrapper (Files): Add m4/largefile.m4.
+ (configure.ac-early): New section.
+
2020-04-10 Bruno Haible <bruno@clisp.org>
MODULES.html.sh: Support for reproducible builds from git-less tarballs.
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#if !(defined _WIN32 || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__)
+# include <sys/stat.h>
+#endif
/* Avoid collision between findprog.c and findprog-lgpl.c. */
#if IN_FINDPROG_LGPL || ! GNULIB_FINDPROG_LGPL
design flaw. */
if (eaccess (progpathname, X_OK) == 0)
{
- /* Found! */
- if (strcmp (progpathname, progname) == 0)
+ /* Check that the progpathname does not point to a directory. */
+ struct stat statbuf;
+
+ if (stat (progpathname, &statbuf) >= 0
+ && ! S_ISDIR (statbuf.st_mode))
{
- 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);
+ /* 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 (path);
- return progpathname;
}
free (progpathname);
/* 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)
{
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
relocwrapper
-> progname
-> progreloc
+ -> stat
+ -> filename
+ -> pathmax
+ -> verify
-> areadlink
-> careadlinkat
-> allocator
-> readlink
-> stat
- -> filename
- -> pathmax
- -> verify
-> canonicalize-lgpl
-> filename
-> malloca
Depends-on:
stdbool
+sys_stat
xalloc
xconcat-filename
access
+stat
unistd
configure.ac:
Depends-on:
stdbool
+sys_stat
strdup
concat-filename
access
+stat
unistd
configure.ac:
lib/setenv.c
lib/c-ctype.h
lib/c-ctype.c
+m4/largefile.m4
m4/malloca.m4
m4/canonicalize.m4
m4/eealloc.m4
verify
xalloc-oversized
+configure.ac-early:
+AC_REQUIRE([AC_SYS_LARGEFILE])
+
configure.ac:
AC_REQUIRE([AC_C_RESTRICT])
gl_FUNC_READLINK_SEPARATE