libpkgconf: path: use realpath(3) to deduplicate the search path

closes #24
feature/tap-sh
William Pitcock 2019-03-23 22:27:05 -05:00
parent ba1f48e48e
commit 3afd14c49e
3 changed files with 8 additions and 7 deletions

2
NEWS
View File

@ -10,6 +10,8 @@ Changes from 1.6.0 to 1.6.1:
- Fixed a regression where having an empty PKG_CONFIG_LIBDIR - Fixed a regression where having an empty PKG_CONFIG_LIBDIR
environment variable would not eliminate the default search environment variable would not eliminate the default search
paths. paths.
- Use POSIX realpath(3) instead of readlink() for deduplicating the
search path. Use _fullpath() on Windows for the same purpose.
Changes from 1.5.4 to 1.6.0: Changes from 1.5.4 to 1.6.0:
---------------------------- ----------------------------

View File

@ -41,6 +41,10 @@ extern "C" {
#define PKG_DIR_SEP_S '/' #define PKG_DIR_SEP_S '/'
#endif #endif
#ifdef _WIN32
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#endif
#define PKGCONF_BUFSIZE (65535) #define PKGCONF_BUFSIZE (65535)
typedef enum { typedef enum {

View File

@ -92,14 +92,9 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter)
return; return;
if (S_ISLNK(st.st_mode)) if (S_ISLNK(st.st_mode))
{ {
char linkdest[PKGCONF_ITEM_SIZE]; char *linkdest = realpath(path, NULL);
ssize_t len;
memset(linkdest, '\0', sizeof linkdest); if (linkdest != NULL && stat(linkdest, &st) == -1)
len = readlink(path, linkdest, sizeof linkdest);
if (len != -1 && (size_t)len < sizeof(linkdest) &&
stat(linkdest, &st) == -1)
return; return;
} }
if (path_list_contains_entry(path, dirlist, &st)) if (path_list_contains_entry(path, dirlist, &st))