Project

General

Profile

Bug #1156

Updated by Tobias Brunner almost 5 years ago

https://github.com/strongswan/strongswan/blob/master/src/libstrongswan/plugins/random/random_rng.c

If 'read' returns -1, then 'got' becomes -1. done will be SIZE_T_MAX (because it is unsigned). The loop will exit and return TRUE without ever allocating random.

For reference, the code:
<pre>


METHOD(rng_t, get_bytes, bool,
private_random_rng_t *this, size_t bytes, u_int8_t *buffer)
{
size_t done;
ssize_t got;

done = 0;

while (done < bytes)
{
got = read(this->fd, buffer + done, bytes - done);
if (got <= 0)
{
DBG1(DBG_LIB, "reading from random FD %d failed: %s, retrying...",
this->fd, strerror(errno));
sleep(1);
}
done += got;
}
return TRUE;
}
</pre>

Back