Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: make arg_parsing.c more robust to crashes

We started getting a crash in BPF CI, which seems to originate from
test_parse_test_list_file() test and is happening at this line:

ASSERT_OK(strcmp("test_with_spaces", set.tests[0].name), "test 0 name");

One way we can crash there is if set.cnt zero, which is checked for with
ASSERT_EQ() above, but we proceed after this regardless of the outcome.
Instead of crashing, we should bail out with test failure early.

Similarly, if parse_test_list_file() fails, we shouldn't be even looking
at set, so bail even earlier if ASSERT_OK() fails.

Fixes: 64276f01dce8 ("selftests/bpf: Test_progs can read test lists from file")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20251014202037.72922-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
e603a342 7f9ee5fc

+6 -3
+6 -3
tools/testing/selftests/bpf/prog_tests/arg_parsing.c
··· 146 146 147 147 init_test_filter_set(&set); 148 148 149 - ASSERT_OK(parse_test_list_file(tmpfile, &set, true), "parse file"); 149 + if (!ASSERT_OK(parse_test_list_file(tmpfile, &set, true), "parse file")) 150 + goto out_fclose; 150 151 151 - ASSERT_EQ(set.cnt, 4, "test count"); 152 + if (!ASSERT_EQ(set.cnt, 4, "test count")) 153 + goto out_free_set; 154 + 152 155 ASSERT_OK(strcmp("test_with_spaces", set.tests[0].name), "test 0 name"); 153 156 ASSERT_EQ(set.tests[0].subtest_cnt, 0, "test 0 subtest count"); 154 157 ASSERT_OK(strcmp("testA", set.tests[1].name), "test 1 name"); ··· 161 158 ASSERT_OK(strcmp("testB", set.tests[2].name), "test 2 name"); 162 159 ASSERT_OK(strcmp("testC_no_eof_newline", set.tests[3].name), "test 3 name"); 163 160 161 + out_free_set: 164 162 free_test_filter_set(&set); 165 - 166 163 out_fclose: 167 164 fclose(fp); 168 165 out_remove: