mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
selftests/bpf: Fix missing allocation null checks in test_progs.c
Add null checks after memory allocations to prevent potential segmentation faults. Fixes:79b4535013("tools/bpf: add a test for bpf_get_stack with tracepoint prog") Fixes:0925225956("bpf/selftests: Add granular subtest output for prog_test") Signed-off-by: Feng Yang <yangfeng@kylinos.cn> Link: https://lore.kernel.org/bpf/20260723085100.482147-4-yangfeng59949@163.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
parent
b04b8d4e19
commit
12b362b2f0
|
|
@ -730,11 +730,14 @@ int compare_map_keys(int map1_fd, int map2_fd)
|
|||
int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len)
|
||||
{
|
||||
__u32 key, next_key, *cur_key_p, *next_key_p;
|
||||
char *val_buf1, *val_buf2;
|
||||
int i, err = 0;
|
||||
char *val_buf1 = NULL, *val_buf2 = NULL;
|
||||
int i, err = -ENOMEM;
|
||||
|
||||
val_buf1 = malloc(stack_trace_len);
|
||||
val_buf2 = malloc(stack_trace_len);
|
||||
if (!val_buf1 || !val_buf2)
|
||||
goto out;
|
||||
err = 0;
|
||||
cur_key_p = NULL;
|
||||
next_key_p = &key;
|
||||
while (bpf_map_get_next_key(smap_fd, cur_key_p, next_key_p) == 0) {
|
||||
|
|
@ -1514,6 +1517,10 @@ static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state)
|
|||
int subtest_num = state->subtest_num;
|
||||
|
||||
state->subtest_states = malloc(subtest_num * sizeof(*subtest_state));
|
||||
if (!state->subtest_states) {
|
||||
state->subtest_num = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (int i = 0; i < subtest_num; i++) {
|
||||
subtest_state = &state->subtest_states[i];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user