In function cgroup_fill_cgc there is an allocation of memory by calling
strdup(ctrl_dir->d_name). 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>
d_name = strdup(ctrl_dir->d_name);
+ if (!d_name) {
+ error = ECGOTHER;
+ cgroup_err("strdup failed to allocate memory: %s\n", strerror(errno));
+ goto fill_error;
+ }
+
if (!strcmp(d_name, ".") || !strcmp(d_name, "..")) {
error = ECGINVAL;
goto fill_error;
fill_error:
if (ctrl_value)
free(ctrl_value);
- free(d_name);
+ if (d_name)
+ free(d_name);
return error;
}