]> git.ipfire.org Git - pakfire.git/commitdiff
file: Perform some basic checks on file paths
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 11:44:19 +0000 (11:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 11:44:19 +0000 (11:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index 90e90aefa47ddc8bf7fa0b3bab7671b63f767e0d..8d38e745d6172eaf8e22929ada811aba59e78bde 100644 (file)
@@ -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);
 }