mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Just use srand on NSE startup in nse_main.cc. This removes the need
for a binding which will probably not be useful for script writers when they have OpenSSL's PRNG already available.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "nmap.h"
|
||||
#include "nbase.h"
|
||||
#include "nmap_error.h"
|
||||
#include "portlist.h"
|
||||
#include "nsock.h"
|
||||
@@ -613,6 +614,13 @@ void script_scan (std::vector<Target *> &targets, stype scantype)
|
||||
assert(L_NSE != NULL);
|
||||
lua_settop(L_NSE, 0); /* clear the stack */
|
||||
|
||||
/*
|
||||
Set the random seed value 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.
|
||||
*/
|
||||
srand(get_random_uint());
|
||||
|
||||
#if 0
|
||||
/* Lua 5.2 */
|
||||
lua_pushcfunction(L_NSE, run_main);
|
||||
|
||||
@@ -95,7 +95,6 @@ local open = io.open;
|
||||
|
||||
local math = require "math";
|
||||
local max = math.max;
|
||||
local randomseed = math.randomseed;
|
||||
|
||||
local package = require "package";
|
||||
|
||||
@@ -124,11 +123,6 @@ 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;
|
||||
|
||||
@@ -8,7 +8,6 @@ extern "C" {
|
||||
#include <math.h>
|
||||
|
||||
#include "nmap.h"
|
||||
#include "nbase.h"
|
||||
#include "nmap_error.h"
|
||||
#include "NmapOps.h"
|
||||
#include "Target.h"
|
||||
@@ -754,12 +753,6 @@ static int l_get_interface (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_get_random_uint (lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, (lua_Number) get_random_uint());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int luaopen_nmap (lua_State *L)
|
||||
{
|
||||
static const luaL_reg nmaplib [] = {
|
||||
@@ -787,7 +780,6 @@ int luaopen_nmap (lua_State *L)
|
||||
{"address_family", l_address_family},
|
||||
{"get_interface", l_get_interface},
|
||||
{"get_interface_info", l_dnet_get_interface_info},
|
||||
{"get_random_uint", l_get_random_uint},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -120,17 +120,6 @@ function get_interface_info(interface_name)
|
||||
-- @return String representing the full path to the file or <code>nil</code>.
|
||||
function fetchfile(filename)
|
||||
|
||||
|
||||
--- Generates a random unsigned integer.
|
||||
--
|
||||
-- This function is generally useful for seeding a random number generator.
|
||||
-- It is not efficient enough to be used as a random number generator.
|
||||
--
|
||||
-- @usage
|
||||
-- nmap.get_rand_uint() --> 1234567890
|
||||
-- @return Number A random unsigned integer.
|
||||
function get_random_uint()
|
||||
|
||||
--- Returns the timing level as a non-negative integer.
|
||||
--
|
||||
-- Possible return values vary from <code>0</code> to <code>5</code>,
|
||||
|
||||
Reference in New Issue
Block a user