RE: [PATCH] bpftool: fix a wrong type cast in btf_dumper_int

John Fastabend
2022-08-25T06:29:41Z

Lam Thai wrote:
> When `data` points to a boolean value, casting it to `int *` is problematic
> and could lead to a wrong value being passed to `jsonw_bool`. Change the
> cast to `bool *` instead.

How is it problematic? Its from BTF_KIND_INT by my quick reading.

>
> Fixes: b12d6ec09730 ("bpf: btf: add btf print functionality")
> Signed-off-by: Lam Thai <lamthai@arista.com>
> ---

for bpf-next looks like a nice cleanup, I don't think its needed for bpf
tree?

> tools/bpf/bpftool/btf_dumper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
> index 125798b0bc5d..19924b6ce796 100644
> --- a/tools/bpf/bpftool/btf_dumper.c
> +++ b/tools/bpf/bpftool/btf_dumper.c
> @@ -452,7 +452,7 @@ static int btf_dumper_int(const struct btf_type *t, __u8 bit_offset,
> *(char *)data);
> break;
> case BTF_INT_BOOL:
> - jsonw_bool(jw, *(int *)data);
> + jsonw_bool(jw, *(bool *)data);
> break;
> default:
> /* shouldn't happen */
>
> base-commit: 6fc2838b148f8fe6aa14fc435e666984a0505018
> --
> 2.37.0
>