Re: [PATCH] libbpf: fix sign expansion bug in btf_dump_get_enum_value()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 19, 2022 at 12:49:34PM +0300, Dan Carpenter wrote:
> The code here is supposed to take a signed int and store it in a
> signed long long.  Unfortunately, the way that the type promotion works
> with this conditional statement is that it takes a signed int, type
> promotes it to a __u32, and then stores that as a signed long long.
> The result is never negative.
> 
> Fixes: d90ec262b35b ("libbpf: Add enum64 support for btf_dump")
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> ---
>  tools/lib/bpf/btf_dump.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
> index 400e84fd0578..627edb5bb6de 100644
> --- a/tools/lib/bpf/btf_dump.c
> +++ b/tools/lib/bpf/btf_dump.c
> @@ -2045,7 +2045,7 @@ static int btf_dump_get_enum_value(struct btf_dump *d,
>  		*value = *(__s64 *)data;
>  		return 0;
>  	case 4:
> -		*value = is_signed ? *(__s32 *)data : *(__u32 *)data;
> +		*value = is_signed ? (__s64)*(__s32 *)data : *(__u32 *)data;
Only case 4 has issues and what does the standard say ?

Do you have a sample dump to debug this that can be pasted in the commit log?

>  		return 0;
>  	case 2:
>  		*value = is_signed ? *(__s16 *)data : *(__u16 *)data;
> -- 
> 2.35.1
> 



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux