mirror of
https://github.com/nmap/nmap.git
synced 2025-12-29 02:49:01 +00:00
use a random number from /dev/urandom (nbase.get_random_uint wrapper)
This commit is contained in:
12
nse_main.lua
12
nse_main.lua
@@ -95,12 +95,7 @@ local open = io.open;
|
||||
|
||||
local math = require "math";
|
||||
local max = math.max;
|
||||
|
||||
-- Due to heap randomization (on most Operating Systems), we can use a
|
||||
-- Lua function address as a good seed for the C srand function. If there
|
||||
-- is no heap randomization, it's still a decently random integer; that is,
|
||||
-- it's no better or worse than os.time().
|
||||
math.randomseed(tonumber(tostring(function() end):match("function: (0x%x+)")));
|
||||
local randomseed = math.randomseed;
|
||||
|
||||
local package = require "package";
|
||||
|
||||
@@ -129,6 +124,11 @@ do -- Append the nselib directory to the Lua search path
|
||||
package.path = path.."?.lua;"..package.path;
|
||||
end
|
||||
|
||||
-- Set the math.randomseed value in nse_main.lua on behalf of scripts.
|
||||
-- Since Lua uses the C rand and srand functions, which have a static
|
||||
-- seed for the entire program, we don't want scripts doing this themselves.
|
||||
math.randomseed(nmap.get_random_uint());
|
||||
|
||||
local script_database_type, script_database_path =
|
||||
cnse.fetchfile_absolute(cnse.script_dbpath);
|
||||
local script_database_update = cnse.scriptupdatedb;
|
||||
|
||||
Reference in New Issue
Block a user