]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
wrapper: fix segfault in cgroup_get_value_bool()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 8 Mar 2023 15:26:24 +0000 (20:56 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 9 Mar 2023 17:15:33 +0000 (10:15 -0700)
The second and third arguments passed to cgroup_get_value_bool() are of
type pointers and the user might pass NULL in place of one or both of
the arguments, 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, "cpuset");
  if (!cgc)
  exit(1);

  ret = cgroup_add_value_string(cgc, "cpuset.cpu_exclusive", "0");
  if (ret)
  exit (1);

  cgroup_get_value_bool(cgc, "cpuset.cpu_exclusive", 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 b701e7de9b9d93aaf2d1cc03f483c7229e6239c3)

src/wrapper.c

index c87cc1e83cb708b15744ff094d0330ee5e5a4ed3..5d8b0023361f06667d2d9d9302ecec20c39f57d0 100644 (file)
@@ -575,7 +575,7 @@ int cgroup_get_value_bool(struct cgroup_controller *controller, const char *name
 {
        int i;
 
-       if (!controller)
+       if (!controller || !name || !value)
                return ECGINVAL;
 
        for (i = 0; i < controller->index; i++) {