libpkgconf: path: relocate the path before doing dedup checks (closes #151)

pull/164/head
William Pitcock 2017-10-16 11:30:22 -05:00
parent 3bc2e21dd1
commit 36551cca83
1 changed files with 7 additions and 7 deletions

View File

@ -80,12 +80,15 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter)
pkgconf_path_t *node; pkgconf_path_t *node;
char path[PKGCONF_BUFSIZE]; char path[PKGCONF_BUFSIZE];
pkgconf_strlcpy(path, text, sizeof path);
pkgconf_path_relocate(path, sizeof path);
#ifdef PKGCONF_CACHE_INODES #ifdef PKGCONF_CACHE_INODES
struct stat st; struct stat st;
if (filter) if (filter)
{ {
if (lstat(text, &st) == -1) if (lstat(path, &st) == -1)
return; return;
if (S_ISLNK(st.st_mode)) if (S_ISLNK(st.st_mode))
{ {
@ -93,23 +96,20 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter)
ssize_t len; ssize_t len;
memset(linkdest, '\0', sizeof linkdest); memset(linkdest, '\0', sizeof linkdest);
len = readlink(text, linkdest, sizeof linkdest); len = readlink(path, linkdest, sizeof linkdest);
if (len != -1 && (size_t)len < sizeof(linkdest) && if (len != -1 && (size_t)len < sizeof(linkdest) &&
stat(linkdest, &st) == -1) stat(linkdest, &st) == -1)
return; return;
} }
if (path_list_contains_entry(text, dirlist, &st)) if (path_list_contains_entry(path, dirlist, &st))
return; return;
} }
#else #else
if (filter && path_list_contains_entry(text, dirlist)) if (filter && path_list_contains_entry(path, dirlist))
return; return;
#endif #endif
pkgconf_strlcpy(path, text, sizeof path);
pkgconf_path_relocate(path, sizeof path);
node = calloc(sizeof(pkgconf_path_t), 1); node = calloc(sizeof(pkgconf_path_t), 1);
node->path = strdup(path); node->path = strdup(path);