random: Properly handle errors when reading from /dev/[u]random

If -1 was returned on the first call to read() `done` got SIZE_MAX
and the function returned TRUE even though no actual random data had
been allocated.

Fixes #1156.
This commit is contained in:
Tobias Brunner
2015-10-29 16:17:17 +01:00
parent 37a22a166b
commit 35dbf8af7a
@@ -56,6 +56,7 @@ METHOD(rng_t, get_bytes, bool,
DBG1(DBG_LIB, "reading from random FD %d failed: %s, retrying...",
this->fd, strerror(errno));
sleep(1);
continue;
}
done += got;
}