]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
wrapper: fix segfault in cgroup_get_value_int64()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 3 Mar 2023 04:31:41 +0000 (10:01 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 6 Mar 2023 14:58:49 +0000 (07:58 -0700)
commitcf616d09d740e7a890e8af3ec9d5799f1713718b
tree26f3151017dd59faa67116c777636ebaacc975c0
parentbcecc2d45b3848c5d1075a6f24f4c2302621fedf
wrapper: fix segfault in cgroup_get_value_int64()

The second and third arguments passed to cgroup_get_value_int64() are of
type char * 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, "cpu");
  if (!cgc)
  exit(1);

  ret = cgroup_add_value_string(cgc, "cpu.shares", "512");
  if (ret)
  exit (1);

  cgroup_get_value_int64(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