[libvirt] [PATCH] util: virrandom: make virRandomBits endian-safe
Pino Toscano
ptoscano at redhat.com
Thu Aug 2 08:02:43 UTC 2018
On Thursday, 2 August 2018 09:56:49 CEST Bjoern Walk wrote:
> Make the generation of random bits in virRandomBits independent of the
> endianness of the running architecture.
>
> This also solves problems with the mocked random byte generation on
> big-endian machines.
>
> Suggested-by: Daniel P. Berrangé <berrange at redhat.com>
> Signed-off-by: Bjoern Walk <bwalk at linux.ibm.com>
> ---
> This goes on top of Michal's fix: https://www.redhat.com/archives/libvir-list/2018-August/msg00080.html
>
> src/util/virrandom.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/util/virrandom.c b/src/util/virrandom.c
> index 7915f653..26ff68f5 100644
> --- a/src/util/virrandom.c
> +++ b/src/util/virrandom.c
> @@ -34,6 +34,7 @@
> # include <gnutls/crypto.h>
> #endif
>
> +#include "virendian.h"
> #include "virrandom.h"
> #include "virthread.h"
> #include "count-one-bits.h"
> @@ -61,13 +62,16 @@ VIR_LOG_INIT("util.random");
> uint64_t virRandomBits(int nbits)
> {
> uint64_t ret = 0;
> + uint8_t val[8];
>
> - if (virRandomBytes((unsigned char *) &ret, sizeof(ret)) < 0) {
> + if (virRandomBytes((unsigned char *) &val, sizeof(val)) < 0) {
> /* You're already hosed, so this particular non-random value
> * isn't any worse. */
> return 0;
> }
>
> + ret = virReadBufInt64LE(val);
> +
I do not think this patch is correct: we are dealing with random bytes,
so there is no "endianness" for them.
--
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180802/68803db9/attachment-0001.sig>
More information about the libvir-list
mailing list