From 1e2d4026f9c914fb5f27f4ecc1d8dc90a4669d8e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Apr 2022 16:33:27 +0200 Subject: util.random: Test whether util.crand works before using it (fix #1734) util.crand can be configured at compile time to use the Linux getrandom() system call, available from Linux 3.17, but it is still possible to load it with an older kernel lacking that system call, where attempting to use it throws an ENOSYS error. By testing for this on load we can fall back to /dev/urandom in this case. --- util/random.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/random.lua b/util/random.lua index 6782d7fa..3305172f 100644 --- a/util/random.lua +++ b/util/random.lua @@ -7,7 +7,7 @@ -- local ok, crand = pcall(require, "util.crand"); -if ok then return crand; end +if ok and pcall(crand.bytes, 1) then return crand; end local urandom, urandom_err = io.open("/dev/urandom", "r"); -- cgit v1.2.3