From: Michael Tremer Date: Tue, 19 Jul 2022 14:21:28 +0000 (+0000) Subject: snapshots: Protect against invalid inputs X-Git-Tag: 0.9.28~674 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b25bf0b6aee96a7006c6e762d688a9d38b7408d;p=pakfire.git snapshots: Protect against invalid inputs Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/snapshot.c b/src/libpakfire/snapshot.c index 3c8e9606e..9a6fc50cb 100644 --- a/src/libpakfire/snapshot.c +++ b/src/libpakfire/snapshot.c @@ -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) diff --git a/tests/libpakfire/snapshot.c b/tests/libpakfire/snapshot.c index b3a761dfa..710b7ba66 100644 --- a/tests/libpakfire/snapshot.c +++ b/tests/libpakfire/snapshot.c @@ -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(); }