forked from ariadne/pkgconf
libpkgconf: use a better check instead of stat() for pkg-config file iteration, avoiding a TOCTOU race condition identified by coverity
parent
eacc5463c3
commit
e87595b3d1
|
@ -16,10 +16,6 @@
|
||||||
#include <libpkgconf/config.h>
|
#include <libpkgconf/config.h>
|
||||||
#include <libpkgconf/libpkgconf.h>
|
#include <libpkgconf/libpkgconf.h>
|
||||||
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
# include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* !doc
|
* !doc
|
||||||
*
|
*
|
||||||
|
@ -450,22 +446,14 @@ pkgconf_pkg_scan_dir(pkgconf_client_t *client, const char *path, void *data, pkg
|
||||||
static char filebuf[PKGCONF_BUFSIZE];
|
static char filebuf[PKGCONF_BUFSIZE];
|
||||||
pkgconf_pkg_t *pkg;
|
pkgconf_pkg_t *pkg;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
struct stat st;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pkgconf_strlcpy(filebuf, path, sizeof filebuf);
|
pkgconf_strlcpy(filebuf, path, sizeof filebuf);
|
||||||
pkgconf_strlcat(filebuf, "/", sizeof filebuf);
|
pkgconf_strlcat(filebuf, "/", sizeof filebuf);
|
||||||
pkgconf_strlcat(filebuf, dirent->d_name, sizeof filebuf);
|
pkgconf_strlcat(filebuf, dirent->d_name, sizeof filebuf);
|
||||||
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
if (!str_has_suffix(filebuf, PKG_CONFIG_EXT))
|
||||||
if (stat(filebuf, &st) == -1)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(S_ISREG(st.st_mode)))
|
|
||||||
continue;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
f = fopen(filebuf, "r");
|
f = fopen(filebuf, "r");
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue