]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
wrapper: fix segfault in cgroup_set_value_string()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 20 Feb 2023 15:09:07 +0000 (15:09 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 22 Feb 2023 16:41:41 +0000 (09:41 -0700)
commit3eabc319b1af5ab8024eb9145e196270c4cdec94
tree07fc4de8ebfb808eb5e77b3dabafc65b9569d6ea
parent62426a9b1395c34b2527eb1b193eaaa8b5906b35
wrapper: fix segfault in cgroup_set_value_string()

The second and third arguments passed to cgroup_set_value_string() are
of type char * and the user might pass NULL in place of one or both of
the arguments, causing a segfault.  segfault is trigger when the NULL,
argument values are used without checks, fix it by checking for NULL
before proceeding.

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

int main(void)
{
        struct cgroup_controller *cgc;
        struct cgroup *cgrp;

        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_create_cgroup(cgrp, 1);
        if (ret)
exit(1);

        cgroup_set_value_string(cgc, NULL, 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>
src/wrapper.c