[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] util: virrandom: make virRandomBits endian-safe



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 redhat com>
> Signed-off-by: Bjoern Walk <bwalk 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

Attachment: signature.asc
Description: This is a digitally signed message part.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]