From 35dbf8af7a9048f3384af181613c352b718f8d8e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 12 Oct 2015 11:04:55 +0200 Subject: [PATCH] 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. --- src/libstrongswan/plugins/random/random_rng.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstrongswan/plugins/random/random_rng.c b/src/libstrongswan/plugins/random/random_rng.c index 36d5446b8..177b3c2e5 100644 --- a/src/libstrongswan/plugins/random/random_rng.c +++ b/src/libstrongswan/plugins/random/random_rng.c @@ -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; }