]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
random-util: handle if getrandom() returns 0
authorLennart Poettering <lennart@poettering.net>
Wed, 7 Nov 2018 17:37:13 +0000 (18:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Nov 2018 08:44:27 +0000 (09:44 +0100)
This should normally not happen, but given that the man page suggests
something about this in the context of interruption, let's handle this
and propagate an I/O error.

src/basic/random-util.c

index 5e4ed2da9d0ef25506b3466c4fc882d165795c08..3989bb9dc6181957e0446199bbce9dbb8278bf95 100644 (file)
@@ -93,6 +93,9 @@ int genuine_random_bytes(void *p, size_t n, bool high_quality_required) {
                         }
 
                         already_done = r;
+                } else if (r == 0) {
+                        have_syscall = true;
+                        return -EIO;
                 } else if (errno == ENOSYS)
                           /* We lack the syscall, continue with reading from /dev/urandom. */
                           have_syscall = false;