]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Store the real path on stack to avoid it being altered later
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 9 Mar 2023 13:43:51 +0000 (13:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 9 Mar 2023 13:44:41 +0000 (13:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/util.h
src/libpakfire/repo.c
src/libpakfire/util.c

index 89ffeb5184fdcc275e35d9431bba8a07c73c5f3d..18b1e5b7de4e2f37c24d8f5ad32f63c49ad5ebab 100644 (file)
@@ -68,6 +68,10 @@ 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);
 
+#define pakfire_path_realpath(dest, path) \
+       __pakfire_path_realpath(dest, sizeof(dest), path)
+int __pakfire_path_realpath(char* dest, const size_t length, const char* path);
+
 // File stuff
 
 int pakfire_file_write(struct pakfire* pakfire, const char* path,
index 950916073f23a3804d4dd4c8f9f53077e3969830..bd467ccea217fb094afeb76d33fcbfd1ab786f98 100644 (file)
@@ -1504,7 +1504,7 @@ ERROR:
 PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* path,
                int flags, const char** files) {
        struct pakfire_repo* repo = NULL;
-       const char* abspath = NULL;
+       char realpath[PATH_MAX];
        char baseurl[PATH_MAX];
        int r;
 
@@ -1523,12 +1523,12 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
        }
 
        // Make path absolute
-       abspath = pakfire_path_abspath(path);
-       if (!abspath)
-               return 1;
+       r = pakfire_path_realpath(realpath, path);
+       if (r)
+               return r;
 
        // Prefix path with file:// to form baseurl
-       r = pakfire_string_format(baseurl, "file://%s", abspath);
+       r = pakfire_string_format(baseurl, "file://%s", realpath);
        if (r)
                return 1;
 
@@ -1581,7 +1581,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
                        const char* filename = pakfire_package_get_string(package, PAKFIRE_PKG_FILENAME);
 
                        // Make new path
-                       r = pakfire_path_join(destination_path, abspath, filename);
+                       r = pakfire_path_join(destination_path, realpath, filename);
                        if (r)
                                goto OUT;
 
index 8fe802f39c7a812fd3ba292bf1bdf36d86595dc4..4711a1d8bd095e4ce9257031c2546649a0052863 100644 (file)
@@ -134,6 +134,17 @@ const char* pakfire_path_relpath(const char* root, const char* path) {
        return NULL;
 }
 
+int __pakfire_path_realpath(char* dest, const size_t length, const char* path) {
+       char buffer[PATH_MAX];
+
+       // Resolve path to its absolute path and store it in buffer
+       char* p = realpath(path, buffer);
+       if (!p)
+               return 1;
+
+       return __pakfire_string_set(dest, length, buffer);
+}
+
 int pakfire_path_exists(const char* path) {
        return !access(path, F_OK);
 }