From: Michael Tremer Date: Thu, 30 Jan 2025 10:18:39 +0000 (+0000) Subject: util: Make sure relative paths are always relative X-Git-Tag: 0.9.30~277 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a5243da06ab601a006598f14b5722c0cb2733f6;p=pakfire.git util: Make sure relative paths are always relative Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/util.c b/src/pakfire/util.c index 931a8974..6e53c626 100644 --- a/src/pakfire/util.c +++ b/src/pakfire/util.c @@ -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,