]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: Don't overflow in virRandomBits
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 1 Aug 2018 11:26:46 +0000 (13:26 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 1 Aug 2018 13:07:19 +0000 (15:07 +0200)
commit78c47a92ecb450c9f8bcabd35da7006dc2547882
tree90807a19eec8fb88de3c9635cf1c205272393a4d
parent3251fc9c9b9639c3fec3181530599415523d671a
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>
src/util/virrandom.c