From cda1ec636a56b80ea89914dcc56bfd01ebbcac06 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Tue, 28 Feb 2023 14:45:11 +0530 Subject: [PATCH] tests/gunit: Extend the fuzzer to test cgroup_get_uid_gid() 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 Signed-off-by: Tom Hromatka (cherry picked from commit 72a3d75036f00541cbc4a0dac3d9c6ca138869e8) --- tests/gunit/017-API_fuzz_test.cpp | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/gunit/017-API_fuzz_test.cpp b/tests/gunit/017-API_fuzz_test.cpp index 64f2ee5c..93e1232c 100644 --- a/tests/gunit/017-API_fuzz_test.cpp +++ b/tests/gunit/017-API_fuzz_test.cpp @@ -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); +} -- 2.47.2