]> git.ipfire.org Git - pakfire.git/commitdiff
util: Make sure relative paths are always relative
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 10:18:39 +0000 (10:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 10:18:39 +0000 (10:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/util.c

index 931a8974db14350977a1798243d3a370fd48e296..6e53c62629fe71c3881260bacaab81eba13a834d 100644 (file)
@@ -46,10 +46,18 @@ const char* pakfire_path_relpath(const char* root, const char* path) {
                return NULL;
        }
 
-       if (pakfire_string_startswith(path, root))
-               return path + strlen(root);
+       // Return NULL if path does not start with root
+       if (!pakfire_string_startswith(path, root))
+               return NULL;
+
+       // Skip the root
+       path += strlen(root);
+
+       // Skip any leading slashes
+       while (path && *path == '/')
+               path++;
 
-       return NULL;
+       return path;
 }
 
 int pakfire_file_write(struct pakfire* pakfire, const char* path,