]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: cgroup_get_current_controller_path: fix a segfault
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 3 May 2023 10:47:06 +0000 (16:17 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 3 May 2023 20:05:01 +0000 (14:05 -0600)
cgroup_get_current_controller_path(pid, controller, current_path), the
third argument isn't currently validated and will cause segfault if the
user passes NULL, in place of expect char **.  Introduce a check to
validate current_path argument too.

Reproducer:
___________
 #include <stdio.h>
 #include <stdlib.h>
 #include <libcgroup.h>

 int main(int argc, char **argv)
 {
  pid_t pid;
  int ret;

  ret = cgroup_init();
  if (ret) {
  printf("cgroup initialization failed:%s\n", cgroup_strerror(ret));
  return ret;
  }

ret = cgroup_get_current_controller_path(atoi(argv[1]), NULL, NULL);
/* should not reach here */
return 0;
 }

 # gcc -o rep rep.c
 # ./rep <valid pid>
 Segmentation fault (core dumped)

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 99ca01b8a911e9996ac6cd47ba4bffc746f4caac..9b830720ad0ed7d45746f2eb7c8e8e8ca777cff5 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -4816,6 +4816,9 @@ int cgroup_get_current_controller_path(pid_t pid, const char *controller, char *
                return ECGROUPNOTINITIALIZED;
        }
 
+       if (!current_path)
+               return ECGOTHER;
+
        mode = cgroup_setup_mode();
        if (mode == CGROUP_MODE_LEGACY && !controller)
                return ECGOTHER;