Skip to content
Snippets Groups Projects
Verified Commit 4b7050ba authored by Petr Špaček's avatar Petr Špaček
Browse files

lua: properly initialize random number generator

Formerly multiple instances could use the same seed,
which prevented the retry logic in Lua modules (e.g. prefill) from
retrying at different times.

AFAIK security impact is zero aside from potential thundering-herd
problem with many kresd instances.
parent aa9e9287
No related branches found
No related tags found
1 merge request!979lua: properly initialize random number generator
Pipeline #62259 failed
......@@ -17,6 +17,7 @@ Bugfixes
- lua resolve(): correctly include EDNS0 in the virtual packet (!963)
Custom modules might have been confused by that.
- do not leak bogus data into SERVFAIL answers (#396)
- improve random Lua number generator initialization (!979)
Incompatible changes
--------------------
......
......@@ -500,6 +500,13 @@ static int init_state(struct engine *engine)
lua_setglobal(engine->L, "map");
lua_pushlightuserdata(engine->L, engine);
lua_setglobal(engine->L, "__engine");
/* Random number generator */
lua_getfield(engine->L, LUA_GLOBALSINDEX, "math");
lua_getfield(engine->L, -1, "randomseed");
lua_remove(engine->L, -2);
lua_Number seed = kr_rand_bytes(sizeof(lua_Number));
lua_pushnumber(engine->L, seed);
lua_call(engine->L, 1, 0);
return kr_ok();
}
......
......@@ -142,10 +142,6 @@ function forward_references.fill_cache()
restart_timer(rz_cur_interval)
end
function prefill.init()
math.randomseed(os.time())
end
function prefill.deinit()
stop_timer()
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment