Message ID | 20200820115843.39454-1-yauheni.kaliuta@redhat.com |
---|---|
State | Accepted |
Delegated to: | BPF Maintainers |
Headers | show |
Series | [v2] bpf: selftests: global_funcs: check err_str before strstr | expand |
On Thu, Aug 20, 2020 at 4:58 AM Yauheni Kaliuta <yauheni.kaliuta@redhat.com> wrote: > > 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 <yauheni.kaliuta@redhat.com> > Acked-by: Yonghong Song <yhs@fb.com> > --- > > v1->v2: > > - remove extra parenthesis; > - remove vague statement from changelog. > > --- > tools/testing/selftests/bpf/prog_tests/test_global_funcs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c b/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c > index 25b068591e9a..2e80a57e5f9d 100644 > --- a/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c > +++ b/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c > @@ -19,7 +19,7 @@ static int libbpf_debug_print(enum libbpf_print_level level, > log_buf = va_arg(args, char *); > if (!log_buf) > goto out; > - if (strstr(log_buf, err_str) == 0) > + if (err_str != NULL && strstr(log_buf, err_str) == 0) I got rid of '!= NULL', since it doesn't fit kernel coding style and applied to bpf tree. Thanks
On Fri, Aug 21, 2020 at 12:34 AM Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: [...] > > - if (strstr(log_buf, err_str) == 0) > > + if (err_str != NULL && strstr(log_buf, err_str) == 0) > > I got rid of '!= NULL', since it doesn't fit kernel coding style and > applied to bpf tree. Thanks Thank you!
diff --git a/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c b/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c index 25b068591e9a..2e80a57e5f9d 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c +++ b/tools/testing/selftests/bpf/prog_tests/test_global_funcs.c @@ -19,7 +19,7 @@ static int libbpf_debug_print(enum libbpf_print_level level, log_buf = va_arg(args, char *); if (!log_buf) goto out; - if (strstr(log_buf, err_str) == 0) + if (err_str != NULL && strstr(log_buf, err_str) == 0) found = true; out: printf(format, log_buf);