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>
return ECGROUPNOTINITIALIZED;
}
+ if (!current_path)
+ return ECGOTHER;
+
mode = cgroup_setup_mode();
if (mode == CGROUP_MODE_LEGACY && !controller)
return ECGOTHER;