]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
tests: jail: A fork bomb should also exhaust all memory
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 16:44:11 +0000 (16:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 16:44:11 +0000 (16:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/jail.c

index aec50e2c8adf03d1c5afc1bdffbbe26421975053..2b5240bc4d7871dd21fd145427a97fc9e99a4921 100644 (file)
@@ -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;