Changeset

10014:5d2f7144fa12 0.11

util.random: Handle unlikely read errors from /dev/urandom (see #1313)
author Kim Alvefur <zash@zash.se>
date Sat, 18 May 2019 17:28:21 +0200
parents 10013:62d8689beafb
children 10015:8297408db58b
files util/random.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/random.lua	Sat May 18 17:45:20 2019 +0200
+++ b/util/random.lua	Sat May 18 17:28:21 2019 +0200
@@ -12,7 +12,11 @@
 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
+		error("Unable to retrieve data from secure random number generator (/dev/urandom): "..err);
+	end
+	return data;
 end
 
 if not urandom then