From 7a5243da06ab601a006598f14b5722c0cb2733f6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 30 Jan 2025 10:18:39 +0000 Subject: [PATCH] util: Make sure relative paths are always relative Signed-off-by: Michael Tremer --- src/pakfire/util.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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, -- 2.39.5