From ec115ffe2ae89ef633d3a7e5a9f01b4e59b62c47 Mon Sep 17 00:00:00 2001 From: Daniel Hajjar <33489389+DanTGL@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:49:15 +0200 Subject: [PATCH] Make SecureRandom non-failable --- doc/lua_api.md | 2 +- src/script/lua_api/l_noise.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 4d461f335..27a9fef96 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -8669,7 +8669,7 @@ In multiplayer mode, the error may be arbitrarily large. Interface for the operating system's crypto-secure PRNG. -It can be created via `SecureRandom()`. The constructor returns nil if a +It can be created via `SecureRandom()`. The constructor throws an error if a secure random device cannot be found on the system. ### Methods diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index 9836f4b09..ead14fec0 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -641,10 +641,9 @@ int LuaSecureRandom::create_object(lua_State *L) { LuaSecureRandom *o = new LuaSecureRandom(); - // Fail and return nil if we can't securely fill the buffer if (!o->fillRandBuf()) { delete o; - return 0; + throw LuaError("SecureRandom: Failed to find secure random device on system"); } *(void **)(lua_newuserdata(L, sizeof(void *))) = o;