lib: bpf_legacy: fix potential NULL-pointer dereference

If bpf_map_fetch_name() returns NULL, strlen() hits a NULL-pointer
dereference on outer_map_name.

Fix this checking outer_map_name value, and returning false when NULL,
as already done for inner_map_name before.

Fixes: 6d61a2b557 ("lib: add libbpf support")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Andrea Claudi 2021-08-07 18:57:38 +02:00 committed by Stephen Hemminger
parent 954a0077c8
commit 50a4127022
1 changed files with 3 additions and 0 deletions

View File

@ -3298,6 +3298,9 @@ bool iproute2_is_map_in_map(const char *libbpf_map_name, struct bpf_elf_map *ima
*omap = ctx->maps[j];
outer_map_name = bpf_map_fetch_name(ctx, j);
if (!outer_map_name)
return false;
memcpy(omap_name, outer_map_name, strlen(outer_map_name) + 1);
return true;