1
0
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:
batrick
2011-05-24 00:09:42 +00:00
parent f482e74821
commit 3b83666a9c
2 changed files with 14 additions and 6 deletions

View File

@@ -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;