Skip to content

Commit 15c3dbf

Browse files
chenyuan0001Kernel Patches Daemon
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. Fix: 351131b ("libbpf: add btf_dump API for BTF-to-C conversion") Signed-off-by: chenyuan <[email protected]>
1 parent 7801208 commit 15c3dbf

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
@@ -227,6 +227,9 @@ static void btf_dump_free_names(struct hashmap *map)
227227
size_t bkt;
228228
struct hashmap_entry *cur;
229229

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

0 commit comments

Comments
 (0)