]> git.ipfire.org Git - pakfire.git/commitdiff
filelist: Scanning requires an absolute path
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Nov 2022 15:46:41 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Nov 2022 15:46:41 +0000 (15:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/filelist.c
src/libpakfire/include/pakfire/util.h
src/libpakfire/util.c

index 0a0890d82edf2d9474f3d5bf50356e2a54fc0cf3..f27266c730e3e42b4d0d4190c2d38d986d1a50fb 100644 (file)
@@ -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;
 
index 38123eb9f74e0d3e613d9267b580fdc3d3d57d14..f713f6dc0506dc780b07c7ccf36643371b938b54 100644 (file)
@@ -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);
 
index 0fd7406da21d61e253674dcf05c851e35dab7b50..efb086faf32e0a11287bbb90bef6cd5802d3baab 100644 (file)
@@ -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;