]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/randutils.c: More paranoia in getrandom() call.
authorChristopher James Halse Rogers <raof@ubuntu.com>
Mon, 7 Aug 2017 06:10:51 +0000 (16:10 +1000)
committerKarel Zak <kzak@redhat.com>
Wed, 20 Sep 2017 12:16:11 +0000 (14:16 +0200)
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.

lib/randutils.c

index ceeb474eff49392f986a11743092dc6efadda94e..7d85dc8417dc00730152303faca034e78a1656d1 100644 (file)
@@ -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;