mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: Don't overflow in virRandomBits
The function is supposed to return up to 64bit long integer. In order to do that it calls virRandomBytes() to fill the integer with random bytes and then masks out everything but requested bits. However, when doing that it shifts 1U and not 1ULL. So effectively, requesting 32 random bis or more always return 0 which is not random enough. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Pino Toscano <ptoscano@redhat.com>
This commit is contained in:
@@ -68,7 +68,7 @@ uint64_t virRandomBits(int nbits)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret &= (1U << nbits) - 1;
|
||||
ret &= (1ULL << nbits) - 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user