random-util: handle if getrandom() returns 0

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.
This commit is contained in:
Lennart Poettering 2018-11-07 18:37:13 +01:00
parent 3335dc2d75
commit d68ccc0841
1 changed files with 3 additions and 0 deletions

View 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;