Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Fix NULL pointer exception in API btf_dump__dump_type_data

We found that function btf_dump__dump_type_data can be called by the
user as an API, but in this function, the `opts` parameter may be used
as a null pointer.This causes `opts->indent_str` to trigger a NULL
pointer exception.

Fixes: 2ce8450ef5a3 ("libbpf: add bpf_object__open_{file, mem} w/ extensible opts")
Signed-off-by: Xin Liu <liuxin350@huawei.com>
Signed-off-by: Weibin Kong <kongweibin2@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220917084809.30770-1-liuxin350@huawei.com

authored by

Xin Liu and committed by
Andrii Nakryiko
7620bffb bc069da6

+1 -1
+1 -1
tools/lib/bpf/btf_dump.c
··· 2385 2385 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0); 2386 2386 2387 2387 /* default indent string is a tab */ 2388 - if (!opts->indent_str) 2388 + if (!OPTS_GET(opts, indent_str, NULL)) 2389 2389 d->typed_dump->indent_str[0] = '\t'; 2390 2390 else 2391 2391 libbpf_strlcpy(d->typed_dump->indent_str, opts->indent_str,