From d25aae15830b1555be6ee2275e725e3ab9b82ab2 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Sat, 4 Mar 2023 12:20:03 +0530 Subject: [PATCH] wrapper: fix segfault in cgroup_get_value_uint64() The second and third arguments passed to cgroup_get_value_uint64() are of type char * and the user might pass NULL in place of one or both of the arguments, causing a segfault. The reason is, argument values are used without checks, fix it by checking for NULL pointers before proceeding. Reproducer: ----------- #include #include int main(void) { struct cgroup_controller *cgc; struct cgroup *cgrp; int ret; ret = cgroup_init(); if (ret) exit(1); cgrp = cgroup_new_cgroup("fuzzer"); if (!cgrp) exit(1); cgc = cgroup_add_controller(cgrp, "cpu"); if (!cgc) exit(1); ret = cgroup_add_value_string(cgc, "cpu.shares", "512"); if (ret) exit (1); cgroup_get_value_uint64(cgc, NULL, NULL); // should not reach here. return 0; } Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit 5ac8e5e4cfca037198b729435bdeb692ec90d351) --- src/wrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrapper.c b/src/wrapper.c index a8b9a54f..7ccad676 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -529,7 +529,7 @@ int cgroup_get_value_uint64(struct cgroup_controller *controller, const char *na { int i; - if (!controller) + if (!controller || !name || !value) return ECGINVAL; for (i = 0; i < controller->index; i++) { -- 2.47.2