From e87595b3d13f1a8bd9ef2a0acc0784f569f53cef Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 23 Jan 2017 12:42:13 -0600 Subject: [PATCH] libpkgconf: use a better check instead of stat() for pkg-config file iteration, avoiding a TOCTOU race condition identified by coverity --- libpkgconf/pkg.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index cc114d9..a574d64 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -16,10 +16,6 @@ #include #include -#ifdef HAVE_SYS_STAT_H -# include -#endif - /* * !doc * @@ -450,22 +446,14 @@ pkgconf_pkg_scan_dir(pkgconf_client_t *client, const char *path, void *data, pkg static char filebuf[PKGCONF_BUFSIZE]; pkgconf_pkg_t *pkg; FILE *f; -#ifdef HAVE_SYS_STAT_H - struct stat st; -#endif pkgconf_strlcpy(filebuf, path, sizeof filebuf); pkgconf_strlcat(filebuf, "/", sizeof filebuf); pkgconf_strlcat(filebuf, dirent->d_name, sizeof filebuf); -#ifdef HAVE_SYS_STAT_H - if (stat(filebuf, &st) == -1) + if (!str_has_suffix(filebuf, PKG_CONFIG_EXT)) continue; - if (!(S_ISREG(st.st_mode))) - continue; -#endif - f = fopen(filebuf, "r"); if (f == NULL) continue;