From a330175614a22c622261e6a70b23c92b2a841bd4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 25 Feb 2017 17:57:22 +0100 Subject: util.crand: Throw error if OpenSSLs RNG is not seeded --- util-src/crand.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'util-src') diff --git a/util-src/crand.c b/util-src/crand.c index cc2047eb..e7caf683 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -67,6 +67,11 @@ int Lrandom(lua_State *L) { arc4random_buf(buf, len); ret = len; #elif defined(WITH_OPENSSL) + if(!RAND_status()) { + lua_pushliteral(L, "OpenSSL PRNG not seeded"); + lua_error(L); + } + ret = RAND_bytes(buf, len); if(ret == 1) { @@ -87,6 +92,7 @@ int luaopen_util_crand(lua_State *L) { #if (LUA_VERSION_NUM > 501) luaL_checkversion(L); #endif + lua_newtable(L); lua_pushcfunction(L, Lrandom); lua_setfield(L, -2, "bytes"); @@ -100,10 +106,6 @@ int luaopen_util_crand(lua_State *L) { #endif lua_setfield(L, -2, "_source"); -#if defined(WITH_OPENSSL) && defined(_WIN32) - /* TODO Do we need to seed this on Windows? */ -#endif - return 1; } -- cgit v1.2.3 From 4707d5665df4179e0b02a520ff36ad51a7b9d9be Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 25 Feb 2017 18:12:24 +0100 Subject: util.crand: Clarify that lua_error does not return --- util-src/crand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util-src') diff --git a/util-src/crand.c b/util-src/crand.c index e7caf683..f3fa00ea 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -69,7 +69,7 @@ int Lrandom(lua_State *L) { #elif defined(WITH_OPENSSL) if(!RAND_status()) { lua_pushliteral(L, "OpenSSL PRNG not seeded"); - lua_error(L); + return lua_error(L); } ret = RAND_bytes(buf, len); -- cgit v1.2.3 From 2b4028fd7e707dc56356330366829f1c93e2d952 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Feb 2017 20:31:08 +0100 Subject: util.pposix: Fix typo in comment --- util-src/pposix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util-src') diff --git a/util-src/pposix.c b/util-src/pposix.c index 5e21be56..10edbd71 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -615,7 +615,7 @@ int lc_getrlimit(lua_State *L) { return 2; } } else { - /* Unsupported resoucrce. Sorry I'm pretty limited by POSIX standard. */ + /* Unsupported resource. Sorry I'm pretty limited by POSIX standard. */ lua_pushboolean(L, 0); lua_pushstring(L, "invalid-resource"); return 2; -- cgit v1.2.3