From: Michael Tremer Date: Tue, 9 Aug 2022 16:44:11 +0000 (+0000) Subject: tests: jail: A fork bomb should also exhaust all memory X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=93550e9b7c66db88080e1967c38ea97566836b82;p=people%2Fstevee%2Fpakfire.git tests: jail: A fork bomb should also exhaust all memory Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/jail.c b/tests/libpakfire/jail.c index aec50e2c..2b5240bc 100644 --- a/tests/libpakfire/jail.c +++ b/tests/libpakfire/jail.c @@ -27,6 +27,14 @@ static const char* cmd_hello_world[] = { "/command", "echo", "Hello World!", NULL, }; +static const char* cmd_exhaust_memory[] = { + "/command", "exhaust-memory", NULL, +}; + +static const char* cmd_fork_bomb[] = { + "/command", "fork-bomb", NULL, +}; + static int test_create(const struct test* t) { struct pakfire_jail* jail = NULL; @@ -164,9 +172,6 @@ static int test_memory_limit(const struct test* t) { struct pakfire_jail* jail = NULL; int r = EXIT_FAILURE; - const char* argv[] = { - "/command", "exhaust-memory", NULL, - }; // Create cgroup ASSERT_SUCCESS(pakfire_cgroup_open(&cgroup, t->pakfire, "pakfire-test", 0)); @@ -181,7 +186,10 @@ static int test_memory_limit(const struct test* t) { ASSERT_SUCCESS(pakfire_cgroup_set_memory_limit(cgroup, 100 * 1024 * 1024)); // Try to exhaust all memory - ASSERT_FAILURE(pakfire_jail_exec(jail, argv, NULL)); + ASSERT_FAILURE(pakfire_jail_exec(jail, cmd_exhaust_memory, NULL)); + + // A fork bomb should also exhaust all memory + ASSERT_FAILURE(pakfire_jail_exec(jail, cmd_fork_bomb, NULL)); // Success r = EXIT_SUCCESS; @@ -202,9 +210,6 @@ static int test_pid_limit(const struct test* t) { struct pakfire_jail* jail = NULL; int r = EXIT_FAILURE; - const char* argv[] = { - "/command", "fork-bomb", NULL, - }; // Create cgroup ASSERT_SUCCESS(pakfire_cgroup_open(&cgroup, t->pakfire, "pakfire-test", 0)); @@ -219,7 +224,7 @@ static int test_pid_limit(const struct test* t) { ASSERT_SUCCESS(pakfire_cgroup_set_pid_limit(cgroup, 100)); // Try to fork as many processes as possible - ASSERT_FAILURE(pakfire_jail_exec(jail, argv, NULL)); + ASSERT_FAILURE(pakfire_jail_exec(jail, cmd_fork_bomb, NULL)); // Success r = EXIT_SUCCESS;