Skip to content

Commit

Permalink
bpftool: Check for NULL ptr of btf in codegen_asserts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Michael Mullin authored and Andrii Nakryiko committed Jun 2, 2022
1 parent eb7b36c commit de4b4b9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/bpf/bpftool/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down

0 comments on commit de4b4b9

Please sign in to comment.