]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
file: Fix tests and handle invalid inputs better
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Aug 2023 17:45:50 +0000 (17:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Aug 2023 17:45:50 +0000 (17:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c
tests/libpakfire/file.c

index 2c985a7cf0133cb967b0d449a5d93dccfef8c8d1..cb3c5e99f768c3661b1506354ea8540ae61dc5e8 100644 (file)
@@ -797,10 +797,8 @@ 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;
-       }
+       if (!path || *path != '/')
+               return -EINVAL;
 
        // Store the abspath
        archive_entry_copy_sourcepath(file->entry, path);
@@ -816,6 +814,10 @@ PAKFIRE_EXPORT int pakfire_file_set_path(struct pakfire_file* file, const char*
        char buffer[PATH_MAX];
        int r = 0;
 
+       // Check input
+       if (!path)
+               return -EINVAL;
+
        // Strip any leading dots from paths
        if (pakfire_string_startswith(path, "./"))
                path++;
index d32f5dd4c9a7225d0c8cf430129e8d0d9a81d6ab..c3f7ba1bf9185421a191c31ad66ad6799dc4e9bd 100644 (file)
@@ -49,10 +49,10 @@ static int test_create_invalid(const struct test* t) {
        ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire));
 
        // Set path
-       ASSERT_ERRNO(pakfire_file_set_path(file, NULL), EINVAL);
+       ASSERT(pakfire_file_set_path(file, NULL) == -EINVAL);
 
        // It should not be possible to set relative absolute paths
-       ASSERT_ERRNO(pakfire_file_set_abspath(file, "abc/abc"), EINVAL);
+       ASSERT(pakfire_file_set_abspath(file, "abc/abc") == -EINVAL);
 
        // Destroy it
        ASSERT_NULL(pakfire_file_unref(file));