In function cg_get_cgroups_from_proc_cgroups there is an allocation of memory by calling
malloc(buff_len).
Result of this allocation is not checked,
and in case of OOM it'll lead to null ptr deref.
This commit adds handling of possible null ptr as a result of failed
memory allocation.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
Acked-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
if (buff_len > 1) {
/* Strip off the leading '/' for every cgroup but the root cgroup */
cgrp_list[idx] = malloc(buff_len);
+ if (!cgrp_list[idx]) {
+ cgroup_err("malloc failed: %s\n", strerror(errno));
+ fclose(f);
+ return ECGOTHER;
+ }
snprintf(cgrp_list[idx], buff_len, "%s", &stok_buff[1]);
} else {
/* Retain the leading '/' since we're in the root cgroup */