]> granicus.if.org Git - libevent/commitdiff
Handle return value from getrandom()
authorGerry Garvey <ggarvey@gmx.com>
Sat, 1 Aug 2020 13:05:39 +0000 (14:05 +0100)
committerPierce Lopez <pierce.lopez@gmail.com>
Sun, 2 Aug 2020 14:02:34 +0000 (10:02 -0400)
arc4random.c

index 8729f6b92fe7584c4870900210e13c15ef72a623..9a00ea2c1074149ef1d62549c3fe32990cea5b51 100644 (file)
@@ -176,25 +176,14 @@ static int
 arc4_seed_getrandom(void)
 {
        unsigned char buf[ADD_ENTROPY];
-       size_t len, n;
-       unsigned i;
-       int any_set;
-
-       memset(buf, 0, sizeof(buf));
+       size_t len;
+       ssize_t n = 0;
 
        for (len = 0; len < sizeof(buf); len += n) {
-               n = sizeof(buf) - len;
-
-               if (0 == getrandom(&buf[len], n, 0))
+               n = getrandom(&buf[len], sizeof(buf) - len, 0);
+               if (n < 0)
                        return -1;
        }
-       /* make sure that the buffer actually got set. */
-       for (i=0,any_set=0; i<sizeof(buf); ++i) {
-               any_set |= buf[i];
-       }
-       if (!any_set)
-               return -1;
-
        arc4_addrandom(buf, sizeof(buf));
        evutil_memclear_(buf, sizeof(buf));
        return 0;