selftests/cgroup: test_zswap: add missing NULL check after malloc()
Subsystems (3)
PATCH 1/1 selftests/cgroup: test_zswap: add missing NULL check after malloc()
In test_per_memcg_writeback(), zw_allocation is allocated via malloc() but its return value is not checked before being used in the subsequent memset() loop. If malloc() fails, this leads to a NULL pointer dereference.
Add the missing NULL check and jump to the existing error cleanup path. This is consistent with the wb_allocation check two lines below.
Fixes a19b47492751 ("selftest/cgroup: fix zswap test_no_invasive_cgroup_shrink on large pagesize system")
Signed-off-by longlong yan <[email protected]>
--- tools/testing/selftests/cgroup/test_zswap.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/cgroup/test_zswap.c +2 -0
@@ -479,6 +479,8 @@ static int test_no_invasive_cgroup_shrink(const char *root)if (cg_enter_current (zw_group)) goto out; zw_allocation =malloc (allocation_size); +if (!zw_allocation) + goto out;for (int i =0 ; i < nr_pages; i++) { off = (unsigned long )i * page_size;memset (&zw_allocation[off],0 , page_size);
Signature · 1 line
2.43.0