Software /
code /
prosody
Diff
util/random.lua @ 10017:994cccebb597
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 26 May 2019 19:41:58 +0200 |
parent | 10016:af8c514e5cf7 |
child | 12446:e54b8a5e35ad |
line wrap: on
line diff
--- a/util/random.lua Mon May 13 12:00:28 2019 +0200 +++ b/util/random.lua Sun May 26 19:41:58 2019 +0200 @@ -12,7 +12,15 @@ local urandom, urandom_err = io.open("/dev/urandom", "r"); local function bytes(n) - return urandom:read(n); + local data, err = urandom:read(n); + if not data then + if err then + error("Unable to retrieve data from secure random number generator (/dev/urandom): "..tostring(err)); + else + error("Secure random number generator (/dev/urandom) returned an end-of-file condition"); + end + end + return data; end if not urandom then