78c47a9 util: Don't overflow in virRandomBits

Authored and Committed by mprivozn 5 years ago
    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>
    
        
file modified
+1 -1