Skip to content

Commit afb30d8

Browse files
mdouchapevik
authored andcommitted
KVM: Fix infinite loop in ptr2hex()
Right shift larger than the left operand size are undefined. 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. Reviewed-by: Cyril Hrubis <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Martin Doucha <[email protected]>
1 parent 7d365d7 commit afb30d8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

testcases/kernel/kvm/lib_guest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ char *ptr2hex(char *dest, uintptr_t val)
8282
uintptr_t tmp;
8383
char *ret = dest;
8484

85-
for (i = 4; val >> i; i += 4)
85+
for (i = 4, tmp = val >> 4; tmp; i += 4, tmp >>= 4)
8686
;
8787

8888
do {

0 commit comments

Comments
 (0)