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

closes #24
pull/188/head
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
environment variable would not eliminate the default search
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:
----------------------------

View File

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

View File

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