mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-01 22:29:06 +08:00
bpf, libbpf: fix segfault in bpf_object__init_maps' pr_debug statement
Ran into it while testing; in bpf_object__init_maps() data can be NULL
in the case where no map section is present. Therefore we simply cannot
access data->d_size before NULL test. Move the pr_debug() where it's
safe to access.
Fixes: d859900c4c56 ("bpf, libbpf: support global data/bss/rodata sections")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Andrii Nakryiko
parent
29e229ef14
commit
72ef206260
@@ -875,14 +875,14 @@ bpf_object__init_maps(struct bpf_object *obj, int flags)
|
|||||||
nr_maps++;
|
nr_maps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Alloc obj->maps and fill nr_maps. */
|
|
||||||
pr_debug("maps in %s: %d maps in %zd bytes\n", obj->path,
|
|
||||||
nr_maps, data->d_size);
|
|
||||||
if (!nr_maps && !nr_maps_glob)
|
if (!nr_maps && !nr_maps_glob)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Assume equally sized map definitions */
|
/* Assume equally sized map definitions */
|
||||||
if (data) {
|
if (data) {
|
||||||
|
pr_debug("maps in %s: %d maps in %zd bytes\n", obj->path,
|
||||||
|
nr_maps, data->d_size);
|
||||||
|
|
||||||
map_def_sz = data->d_size / nr_maps;
|
map_def_sz = data->d_size / nr_maps;
|
||||||
if (!data->d_size || (data->d_size % nr_maps) != 0) {
|
if (!data->d_size || (data->d_size % nr_maps) != 0) {
|
||||||
pr_warning("unable to determine map definition size "
|
pr_warning("unable to determine map definition size "
|
||||||
|
|||||||
Reference in New Issue
Block a user