]> git.ipfire.org Git - pakfire.git/commitdiff
snapshots: Protect against invalid inputs
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jul 2022 14:21:28 +0000 (14:21 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jul 2022 14:21:28 +0000 (14:21 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/snapshot.c
tests/libpakfire/snapshot.c

index 3c8e9606e01e495a7181bd76225f8be12e797ac2..9a6fc50cb32bf9f22656b405ae6bb84c6e5936c2 100644 (file)
@@ -109,6 +109,11 @@ ERROR:
 int pakfire_snapshot_create(struct pakfire* pakfire, FILE* f) {
        int r = 1;
 
+       if (!f) {
+               errno = EINVAL;
+               return 1;
+       }
+
        const char* root = pakfire_get_path(pakfire);
 
        INFO(pakfire, "Creating snapshot of %s...\n", root);
@@ -315,6 +320,11 @@ ERROR:
 int pakfire_snapshot_restore(struct pakfire* pakfire, FILE* f) {
        struct pakfire_db* db = NULL;
 
+       if (!f) {
+               errno = EINVAL;
+               return 1;
+       }
+
        // Extract the archive
        int r = pakfire_snapshot_extract(pakfire, f);
        if (r)
index b3a761dfa7ea77a698e42bde3de76d6d92fa3620..710b7ba66ee9a40153d3332054943b6d9cfe0553 100644 (file)
@@ -57,8 +57,25 @@ FAIL:
        return r;
 }
 
+static int test_invalid_inputs(const struct test* t) {
+       int r = EXIT_FAILURE;
+
+       // pakfire_snapshot_create
+       ASSERT_ERRNO(pakfire_snapshot_create(t->pakfire, NULL), EINVAL);
+
+       // pakfire_snapshot_restore
+       ASSERT_ERRNO(pakfire_snapshot_restore(t->pakfire, NULL), EINVAL);
+
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       return r;
+}
+
 int main(int argc, char** argv) {
        testsuite_add_test(test_create_and_restore);
+       testsuite_add_test(test_invalid_inputs);
 
        return testsuite_run();
 }