bpftool: Check for NULL ptr of btf in codegen_asserts

bpf_object__btf() can return a NULL value.  If bpf_object__btf returns
null, do not progress through codegen_asserts(). This avoids a null ptr
dereference at the call btf__type_cnt() in the function find_type_for_map()

Signed-off-by: Michael Mullin <masmullin@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220523194917.igkgorco42537arb@jup
This commit is contained in:
Michael Mullin 2022-05-23 15:49:17 -04:00 committed by Andrii Nakryiko
parent eb7b36ce47
commit de4b4b94fa

View File

@ -474,6 +474,9 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
const struct btf_type *sec;
char map_ident[256], var_ident[256];
if (!btf)
return;
codegen("\
\n\
__attribute__((unused)) static void \n\