From: Kamalesh Babulal Date: Tue, 7 Mar 2023 05:32:09 +0000 (+0530) Subject: wrapper: fix segfault in cgroup_set_value_bool() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff1202017c45fb9f4644c13d5aaa1d6e63b86242;p=thirdparty%2Flibcgroup.git wrapper: fix segfault in cgroup_set_value_bool() The second argument passed to cgroup_set_value_bool() 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, "cpuset"); if (!cgc) exit(1); ret = cgroup_add_value_string(cgc, "cpuset.cpu_exclusive", "0"); if (ret) exit (1); cgroup_set_value_bool(cgc, NULL, 0); //should not reach here return 0; } Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit 6b5762ceaca18122b8d7a233b1d3453945594d32) --- diff --git a/src/wrapper.c b/src/wrapper.c index 7ccad676..c87cc1e8 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -604,7 +604,7 @@ int cgroup_set_value_bool(struct cgroup_controller *controller, const char *name int ret; int i; - if (!controller) + if (!controller || !name) return ECGINVAL; for (i = 0; i < controller->index; i++) {