提交 78c47a92 编写于 作者: M Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Reviewed-by: NPino Toscano <ptoscano@redhat.com>
上级 3251fc9c
......@@ -68,7 +68,7 @@ uint64_t virRandomBits(int nbits)
return 0;
}
ret &= (1U << nbits) - 1;
ret &= (1ULL << nbits) - 1;
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册