]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
wrapper: fix segfault in cgroup_add_controller()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 24 Feb 2023 05:35:02 +0000 (11:05 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 24 Feb 2023 15:36:39 +0000 (08:36 -0700)
The second argument passed to cgroup_add_controller() is of type
char * and the user might pass NULL in place of the arguments, causing
a segfault.  segfault is trigger when the NULL, argument values is used
without checks, fix it by checking for NULL before proceeding.

Reproducer:
-----------

int main(void)
{
struct cgroup_controller *cgc;
struct cgroup *cgrp;
int 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);

cgroup_add_controller(cgrp, NULL);

// should not reach here
return 0;
}

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

src/wrapper.c

index c97b529ea5fabbc2446c1aaed4f0596484e45fd2..2038ae787dfdcea2f3f4d5097916d3a7b0a8b3a8 100644 (file)
@@ -63,7 +63,7 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup, const cha
        struct cgroup_controller *controller;
        int i, ret;
 
-       if (!cgroup)
+       if (!cgroup || !name)
                return NULL;
 
        /* Still not sure how to handle the failure here. */