Skip to content

Commit c210773

Browse files
Yauheni KaliutaAlexei Starovoitov
authored andcommitted
bpf: selftests: global_funcs: Check err_str before strstr
The error path in libbpf.c:load_program() has calls to pr_warn() which ends up for global_funcs tests to test_global_funcs.c:libbpf_debug_print(). For the tests with no struct test_def::err_str initialized with a string, it causes call of strstr() with NULL as the second argument and it segfaults. Fix it by calling strstr() only for non-NULL err_str. Signed-off-by: Yauheni Kaliuta <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent c8a36f1 commit c210773

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/testing/selftests/bpf/prog_tests/test_global_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int libbpf_debug_print(enum libbpf_print_level level,
1919
log_buf = va_arg(args, char *);
2020
if (!log_buf)
2121
goto out;
22-
if (strstr(log_buf, err_str) == 0)
22+
if (err_str && strstr(log_buf, err_str) == 0)
2323
found = true;
2424
out:
2525
printf(format, log_buf);

0 commit comments

Comments
 (0)