]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
wrapper: fix segfault in cgroup_set_value_bool()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 7 Mar 2023 05:32:09 +0000 (11:02 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 8 Mar 2023 14:27:56 +0000 (07:27 -0700)
commit6b5762ceaca18122b8d7a233b1d3453945594d32
treee57a36b4d5f80ee5d754410611ab188b3c25f55e
parentbc414f494686c3bc66f2747b61c80a4f6e9118f5
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 <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_set_value_bool(cgc, NULL, 0);
  //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