Skip to content

Commit aa485e8

Browse files
chenyuan0001anakryiko
authored andcommitted
libbpf: Fix null pointer dereference in btf_dump__free on allocation failure
When btf_dump__new() fails to allocate memory for the internal hashmap (btf_dump->type_names), it returns an error code. However, the cleanup function btf_dump__free() does not check if btf_dump->type_names is NULL before attempting to free it. This leads to a null pointer dereference when btf_dump__free() is called on a btf_dump object. Fixes: 351131b ("libbpf: add btf_dump API for BTF-to-C conversion") Signed-off-by: Yuan Chen <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent d4adf1c commit aa485e8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tools/lib/bpf/btf_dump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ static void btf_dump_free_names(struct hashmap *map)
226226
size_t bkt;
227227
struct hashmap_entry *cur;
228228

229+
if (!map)
230+
return;
231+
229232
hashmap__for_each_entry(map, cur, bkt)
230233
free((void *)cur->pkey);
231234

0 commit comments

Comments
 (0)