]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
file: Fix path when opening a file inside the jail
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 16:39:07 +0000 (16:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Dec 2024 16:39:07 +0000 (16:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index cda47938818b357e00cd4c87aa6ea535b5401982..9b06d4d09157339ddfbf3b5e3d2f25c4e97484cd 100644 (file)
@@ -1081,10 +1081,20 @@ static int pakfire_file_levels(struct pakfire_file* file) {
 }
 
 FILE* pakfire_file_open(struct pakfire_file* file) {
-       const char* path = pakfire_file_get_abspath(file);
+       const char* path = NULL;
+
+       // Fetch the absolute path of the file
+       path = pakfire_file_get_abspath(file);
        if (!path)
                return NULL;
 
+       // Fix the path if we have entered the jail
+       if (pakfire_ctx_has_flag(file->ctx, PAKFIRE_CTX_IN_JAIL)) {
+               path = pakfire_relpath(file->pakfire, path);
+               if (!path)
+                       return NULL;
+       }
+
        FILE* f = fopen(path, "r+");
        if (!f)
                ERROR(file->ctx, "Could not open %s: %m\n", path);