bpf: selftests: global_funcs: Check err_str before strstr
authorYauheni Kaliuta <yauheni.kaliuta@redhat.com>
Thu, 20 Aug 2020 11:58:43 +0000 (14:58 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:29:38 +0000 (11:29 +0200)
commit736d8a6a73be34333e6df0849c8d0efe41ea6ac1
tree7599d8db32b5efbadd149f6059925ab020325bc7
parentd5a4d2f25d77133364a1a25d053818981e4bca44
bpf: selftests: global_funcs: Check err_str before strstr

[ Upstream commit c210773d6c6f595f5922d56b7391fe343bc7310e ]

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>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200820115843.39454-1-yauheni.kaliuta@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/bpf/prog_tests/test_global_funcs.c