From: Michael Tremer Date: Sun, 29 Dec 2024 16:39:07 +0000 (+0000) Subject: file: Fix path when opening a file inside the jail X-Git-Tag: 0.9.30~669 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70638a60b2eb806dcab8bd519261d7f72139e916;p=pakfire.git file: Fix path when opening a file inside the jail Signed-off-by: Michael Tremer --- 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);