From 12ef4ab7c6c5151d009d97fc9cae38dceeb36f14 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Thu, 2 Mar 2023 10:34:49 +0530 Subject: [PATCH] wrapper: fix segfault in cgroup_set_value_int64() The second argument passed to cgroup_set_value_int64() is of type char * and the user might pass NULL in the place of the argument, 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_set_value_int64(cgc, NULL, 512); // should not reach here. return 0; } Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit 3d56cb07193682da2df078820427e45b458b5823) --- src/wrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrapper.c b/src/wrapper.c index 324b881e..677ba2a0 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -505,7 +505,7 @@ int cgroup_set_value_int64(struct cgroup_controller *controller, const char *nam int ret; int i; - if (!controller) + if (!controller || !name) return ECGINVAL; for (i = 0; i < controller->index; i++) { -- 2.47.2