From d13bd5b7130bde745a00a56d81acf95062179d95 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 19 Aug 2022 11:44:19 +0000 Subject: [PATCH] file: Perform some basic checks on file paths Signed-off-by: Michael Tremer --- src/libpakfire/file.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 90e90aefa..8d38e745d 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -272,6 +272,12 @@ const char* pakfire_file_get_abspath(struct pakfire_file* file) { } int pakfire_file_set_abspath(struct pakfire_file* file, const char* path) { + // Check if path is set and absolute + if (!path || *path != '/') { + errno = EINVAL; + return 1; + } + return pakfire_string_set(file->abspath, path); } @@ -280,6 +286,12 @@ PAKFIRE_EXPORT const char* pakfire_file_get_path(struct pakfire_file* file) { } PAKFIRE_EXPORT int pakfire_file_set_path(struct pakfire_file* file, const char* path) { + // Check if path is set and absolute + if (!path || *path != '/') { + errno = EINVAL; + return 1; + } + return pakfire_string_set(file->path, path); } -- 2.47.3