mirror of https://gitee.com/openkylin/libvirt.git
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:
parent
3251fc9c9b
commit
78c47a92ec
|
@ -68,7 +68,7 @@ uint64_t virRandomBits(int nbits)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ret &= (1U << nbits) - 1;
|
||||
ret &= (1ULL << nbits) - 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue