]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tests/gunit: Extend the fuzzer to test cgroup_get_uid_gid()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 28 Feb 2023 09:15:11 +0000 (14:45 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 28 Feb 2023 22:24:59 +0000 (15:24 -0700)
Add fuzzing to the cgroup_get_uid_gid() API, by passing combination of
of valid/NULL as arguments to the API.

[----------] 7 tests from APIArgsTest
[ RUN      ] APIArgsTest.API_cgroup_set_permissions
[       OK ] APIArgsTest.API_cgroup_set_permissions (0 ms)
[ RUN      ] APIArgsTest.API_cgroup_new_cgroup
[       OK ] APIArgsTest.API_cgroup_new_cgroup (0 ms)
[ RUN      ] APIArgsTest.API_cgroup_set_value_string
[       OK ] APIArgsTest.API_cgroup_set_value_string (0 ms)
[ RUN      ] APIArgsTest.API_cgroup_get_value_string
[       OK ] APIArgsTest.API_cgroup_get_value_string (0 ms)
[ RUN      ] APIArgsTest.API_cgroup_add_controller
[       OK ] APIArgsTest.API_cgroup_add_controller (0 ms)
[ RUN      ] APIArgsTest.API_cgroup_add_value_string
[       OK ] APIArgsTest.API_cgroup_add_value_string (0 ms)
[ RUN      ] APIArgsTest.API_cgroup_get_uid_gid
[       OK ] APIArgsTest.API_cgroup_get_uid_gid (0 ms)

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 72a3d75036f00541cbc4a0dac3d9c6ca138869e8)

tests/gunit/017-API_fuzz_test.cpp

index 64f2ee5ce7d15ef5c8e4127ffd5935c45e740576..93e1232c3a36a3a8e593fecc2416b210f7b1e35d 100644 (file)
@@ -267,3 +267,51 @@ TEST_F(APIArgsTest, API_cgroup_add_value_string)
 
        free(ctrl_value);
 }
+
+TEST_F(APIArgsTest, API_cgroup_get_uid_gid)
+{
+       const char * const cg_name = "FuzzerCgroup";
+       uid_t tasks_uid, control_uid;
+       gid_t tasks_gid, control_gid;
+
+       struct cgroup *cgroup = NULL;
+       int ret;
+       // case 1
+       // cgroup = NULL, tasks_uid = NULL, tasks_gid = NULL, control_uid = NULL,
+       // control_uid = NULL
+       ret = cgroup_get_uid_gid(cgroup, NULL, NULL, NULL, NULL);
+       ASSERT_EQ(ret, 50011);
+
+       // case 2
+       // cgroup = valid, tasks_uid = NULL, tasks_gid = NULL, control_uid = NULL,
+       // control_uid = NULL
+       cgroup = cgroup_new_cgroup(cg_name);
+       ASSERT_NE(cgroup, nullptr);
+
+       ret = cgroup_get_uid_gid(cgroup, NULL, NULL, NULL, NULL);
+       ASSERT_EQ(ret, 50011);
+
+       // case 3
+       // cgroup = valid, tasks_uid = valid, tasks_gid = NULL, control_uid = NULL,
+       // control_uid = NULL
+       ret = cgroup_get_uid_gid(cgroup, &tasks_uid, NULL, NULL, NULL);
+       ASSERT_EQ(ret, 50011);
+
+       // case 4
+       // cgroup = valid, tasks_uid = valid, tasks_gid = valid, control_uid = NULL,
+       // control_uid = NULL
+       ret = cgroup_get_uid_gid(cgroup, &tasks_uid, &tasks_gid, NULL, NULL);
+       ASSERT_EQ(ret, 50011);
+
+       // case 5
+       // cgroup = valid, tasks_uid = valid, tasks_gid = valid, control_uid = valid,
+       // control_uid = NULL
+       ret = cgroup_get_uid_gid(cgroup, &tasks_uid, &tasks_gid, &control_uid, NULL);
+       ASSERT_EQ(ret, 50011);
+
+       // case 6
+       // cgroup = valid, tasks_uid = valid, tasks_gid = valid, control_uid = valid,
+       // control_uid = valid
+       ret = cgroup_get_uid_gid(cgroup, &tasks_uid, &tasks_gid, &control_uid, &control_gid);
+       ASSERT_EQ(ret, 0);
+}