Skip to contentSkip to conversation

libbpf: Fix signedness bug in btf_dump_array_data()

PATCH Applied Dan Carpenter 3 participants 3 messages Feb 8, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Fix signedness bug in btf_dump_array_data()

The btf__resolve_size() function returns negative error codes so "elem_size" must be signed for the error handling to work.

Fixes 920d16af9b42 ("libbpf: BTF dumper support for typed data")
---
 tools/lib/bpf/btf_dump.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/lib/bpf/btf_dump.c +3 -2
index b9a3260c83cb..55aed9e398c3 100644
@@ -1861,14 +1861,15 @@ static int btf_dump_array_data(struct btf_dump *d,
 {
 	const struct btf_array *array = btf_array(t);
 	const struct btf_type *elem_type;
-	__u32 i, elem_size = 0, elem_type_id;
+	__u32 i, elem_type_id;
+	__s64 elem_size;
 	bool is_array_member;
 
 	elem_type_id = array->type;
 	elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL);
 	elem_size = btf__resolve_size(d->btf, elem_type_id);
 	if (elem_size <= 0) {
-		pr_warn("unexpected elem size %d for array type [%u]\n", elem_size, id);
+		pr_warn("unexpected elem size %lld for array type [%u]\n", elem_size, id);
 		return -EINVAL;
 	}
 
Signature · 1 line
2.20.1
#2 lore raw
In reply to Dan Carpenter
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Tue, 8 Feb 2022 10:15:52 +0300 you wrote:

The btf__resolve_size() function returns negative error codes so "elem_size" must be signed for the error handling to work.

Fixes 920d16af9b42 ("libbpf: BTF dumper support for typed data")
---
 tools/lib/bpf/btf_dump.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Here is the summary with links:
- libbpf: Fix signedness bug in btf_dump_array_data()

    https://git.kernel.org/bpf/bpf-next/c/4172843ed4a3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html