Handle return value from getrandom()

This commit is contained in:
Gerry Garvey 2020-08-01 14:05:39 +01:00 committed by Pierce Lopez
parent 62c152d9a7
commit efa57159dd

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