mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Handle return value from getrandom()
This commit is contained in:
parent
62c152d9a7
commit
efa57159dd
19
arc4random.c
19
arc4random.c
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user