lib/randutils.c: Improvements for getrandom usage #492

Merged
merged 2 commits into from Aug 10, 2017

Conversation

2 participants
Contributor

RAOF commented Aug 7, 2017

  1. Use the previous “read from /dev/urandom” codepath on kernels which don't support the getrandom() syscall.
  2. Check that getrandom() read the number of bytes requested.

RAOF added some commits Aug 7, 2017

lib/randutils.c: Fall back gracefully when kernel doesn't support get…
…random(2).

The 3.16 kernel is supported until 2020, and various distros have kernels of the same
vintage. It's entirely possible for code built against newer headers to be run against
these kernels, so fall-back to the old “read /dev/{u,}random” method if the kernel doesn'
support getrandom()
lib/randutils.c: More paranoia in getrandom() call.
If getrandom() is called with nbytes ≥ 256 then it can return with less than the requested
bytes filled.

In this case we *could* adjust the buffer by the number of bytes actually read, but it's
simpler to just redo the call.

@karelzak karelzak merged commit cc7d1fd into karelzak:master Aug 10, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment