summaryrefslogtreecommitdiffstats
path: root/lib/randutils.c
diff options
context:
space:
mode:
authorChristopher James Halse Rogers2017-08-07 08:10:51 +0200
committerChristopher James Halse Rogers2017-08-08 03:28:25 +0200
commitcc7d1fd16d14acf08a20fbe3a6426d2cb4878768 (patch)
tree1e6d2bc83fcc135da78719b96f59d62b43615e3d /lib/randutils.c
parentlib/randutils.c: Fall back gracefully when kernel doesn't support getrandom(2). (diff)
downloadkernel-qcow2-util-linux-cc7d1fd16d14acf08a20fbe3a6426d2cb4878768.tar.gz
kernel-qcow2-util-linux-cc7d1fd16d14acf08a20fbe3a6426d2cb4878768.tar.xz
kernel-qcow2-util-linux-cc7d1fd16d14acf08a20fbe3a6426d2cb4878768.zip
lib/randutils.c: More paranoia in getrandom() call.
If getrandom() is called with nbytes ≥ 256 then it can return with less than the requested bytes filled. In this case we *could* adjust the buffer by the number of bytes actually read, but it's simpler to just redo the call.
Diffstat (limited to 'lib/randutils.c')
-rw-r--r--lib/randutils.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/randutils.c b/lib/randutils.c
index ceeb474ef..7d85dc841 100644
--- a/lib/randutils.c
+++ b/lib/randutils.c
@@ -100,7 +100,7 @@ void random_get_bytes(void *buf, size_t nbytes)
#ifdef HAVE_GETRANDOM
errno = 0;
- while (getrandom(buf, nbytes, 0) < 0) {
+ while (getrandom(buf, nbytes, 0) != (ssize_t)nbytes) {
if (errno == EINTR)
continue;
break;