mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 11:03:07 -04:00
selftests/bpf: Use calloc to allocate subtest_states
An early return triggered by read_prog_test_msg leaves uninitialized elements, which leads to memory corruption during free_test_states cleanup. Signed-off-by: Feng Yang <yangfeng@kylinos.cn> Link: https://lore.kernel.org/bpf/20260723085100.482147-5-yangfeng59949@163.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
committed by
Kumar Kartikeya Dwivedi
parent
12b362b2f0
commit
a813ad2185
@@ -1516,7 +1516,7 @@ static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state)
|
||||
struct subtest_state *subtest_state;
|
||||
int subtest_num = state->subtest_num;
|
||||
|
||||
state->subtest_states = malloc(subtest_num * sizeof(*subtest_state));
|
||||
state->subtest_states = calloc(subtest_num, sizeof(*subtest_state));
|
||||
if (!state->subtest_states) {
|
||||
state->subtest_num = 0;
|
||||
return -ENOMEM;
|
||||
@@ -1525,8 +1525,6 @@ static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state)
|
||||
for (int i = 0; i < subtest_num; i++) {
|
||||
subtest_state = &state->subtest_states[i];
|
||||
|
||||
memset(subtest_state, 0, sizeof(*subtest_state));
|
||||
|
||||
if (read_prog_test_msg(sock_fd, &msg, MSG_SUBTEST_DONE))
|
||||
return 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user