[LTP] [PATCH 3/5] KVM: Fix infinite loop in ptr2hex()

Cyril Hrubis chrubis@suse.cz
Wed Apr 26 09:57:38 CEST 2023


Hi!
> Contrary to the C standard, (x >> 64) is equivalent to (x >> 0) on x86.

As far as I can tell right shift larger than the left operand size are
undefined, at least in C99.

Other than that the patch looks good.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

> This can cause infinite loop in ptr2hex() if the highest nibble
> in the second argument is non-zero. Use temporary variable to avoid
> bit-shifting by large values.
> 
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
>  testcases/kernel/kvm/lib_guest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/kvm/lib_guest.c b/testcases/kernel/kvm/lib_guest.c
> index d237293fc..d3b2ac3d5 100644
> --- a/testcases/kernel/kvm/lib_guest.c
> +++ b/testcases/kernel/kvm/lib_guest.c
> @@ -82,7 +82,7 @@ char *ptr2hex(char *dest, uintptr_t val)
>  	uintptr_t tmp;
>  	char *ret = dest;
>  
> -	for (i = 4; val >> i; i += 4)
> +	for (i = 4, tmp = val >> 4; tmp; i += 4, tmp >>= 4)
>  		;
>  
>  	do {
> -- 
> 2.40.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list