]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
wrapper: fix segfault in cgroup_set_value_uint64()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Sat, 4 Mar 2023 04:18:53 +0000 (09:48 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 6 Mar 2023 15:03:30 +0000 (08:03 -0700)
commitafb6c6ab0ca1c7812bb8229c7054ba4917402f67
tree86895610dbfe4bb6712e5c57cc4a9801bb2bac29
parentf9c1524f8e8c855885982ace43ca655bea077468
wrapper: fix segfault in cgroup_set_value_uint64()

The second argument passed to cgroup_set_value_uint64() 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 <stdlib.h>
 #include <libcgroup.h>

 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_uint64(cgc, NULL, 512);
         // 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