summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMichael Mullin <masmullin@gmail.com>2022-05-23 22:49:17 +0300
committerAndrii Nakryiko <andrii@kernel.org>2022-06-03 02:26:43 +0300
commitde4b4b94fad90f876ab12e87999109e31a1871b4 (patch)
tree1b795412ac72bdd5858073682f4b274b6d93d629 /tools
parenteb7b36ce47f830a01ad9405e673b563cc3638d5d (diff)
downloadlinux-de4b4b94fad90f876ab12e87999109e31a1871b4.tar.xz
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
Diffstat (limited to 'tools')
-rw-r--r--tools/bpf/bpftool/gen.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 4c9477ff748d..f158dc1c2149 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -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\