[LTP] [PATCH 3/5] KVM: Fix infinite loop in ptr2hex()
Martin Doucha
mdoucha@suse.cz
Fri Apr 21 16:57:44 CEST 2023
Contrary to the C standard, (x >> 64) is equivalent to (x >> 0) on x86.
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
More information about the ltp
mailing list