From 70638a60b2eb806dcab8bd519261d7f72139e916 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 29 Dec 2024 16:39:07 +0000 Subject: [PATCH] file: Fix path when opening a file inside the jail Signed-off-by: Michael Tremer --- src/libpakfire/file.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index cda479388..9b06d4d09 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -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); -- 2.47.3