aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2022-04-02 16:33:27 +0200
committerKim Alvefur <zash@zash.se>2022-04-02 16:33:27 +0200
commit1e2d4026f9c914fb5f27f4ecc1d8dc90a4669d8e (patch)
treefe8a0c20524b78d8f0e3a0903ada21550aea3587 /util
parentf19f1088b757c41c2c63b328f1d3faca8fe9a857 (diff)
downloadprosody-1e2d4026f9c914fb5f27f4ecc1d8dc90a4669d8e.tar.gz
prosody-1e2d4026f9c914fb5f27f4ecc1d8dc90a4669d8e.zip
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.
Diffstat (limited to 'util')
-rw-r--r--util/random.lua2
1 files changed, 1 insertions, 1 deletions
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");