From 86f7f0cee3a9e6294e3ac46683bcabfceb977d42 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 21 Nov 2022 15:46:41 +0000 Subject: [PATCH] filelist: Scanning requires an absolute path Signed-off-by: Michael Tremer --- src/libpakfire/filelist.c | 12 ++++++++++-- src/libpakfire/include/pakfire/util.h | 1 + src/libpakfire/util.c | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index 0a0890d82..f27266c73 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -233,6 +233,12 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, struct archive_entry* entry = NULL; int r = 1; + // Root must be absolute + if (!pakfire_path_is_absolute(root)) { + errno = EINVAL; + return 1; + } + DEBUG(list->pakfire, "Scanning %s...\n", root); if (includes) { @@ -267,14 +273,16 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, if (!tree) goto ERROR; - FTSENT* node; + FTSENT* node = NULL; + const char* path = NULL; + while ((node = fts_read(tree))) { // Ignore any directories in post order if (node->fts_info == FTS_DP) continue; // Compute the relative path - const char* path = pakfire_path_relpath(root, node->fts_path); + path = pakfire_path_relpath(root, node->fts_path); if (!path || !*path) continue; diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 38123eb9f..f713f6dc0 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -55,6 +55,7 @@ int __pakfire_unhexlify(unsigned char* dst, const size_t l, const char* src); __pakfire_path_join(dest, sizeof(dest), first, second) int __pakfire_path_join(char* dest, const size_t length, const char* first, const char* second); +int pakfire_path_is_absolute(const char* path); const char* pakfire_path_abspath(const char* path); const char* pakfire_path_relpath(const char* root, const char* path); diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 0fd7406da..efb086faf 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -86,6 +86,15 @@ int __pakfire_path_join(char* dest, const size_t length, return __pakfire_string_format(dest, length, "%s/%s", first, second); } +int pakfire_path_is_absolute(const char* path) { + if (!path) { + errno = EINVAL; + return -1; + } + + return (*path == '/'); +} + const char* pakfire_path_abspath(const char* path) { static char buffer[PATH_MAX]; int r; -- 2.39.5