random: Properly handle errors when reading from /dev/[u]random
authorTobias Brunner <tobias@strongswan.org>
Mon, 12 Oct 2015 09:04:55 +0000 (11:04 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 29 Oct 2015 15:17:17 +0000 (16:17 +0100)
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

index 36d5446..177b3c2 100644 (file)
@@ -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;
        }