1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 13:11:28 +00:00

Fix a bug which caused some NSE scripts to fail, due to the absence of

the NSE SCRIPT_NAME environment variable when the scripts are loaded.
Reported by Michael Pattrick.
This commit is contained in:
djalal
2011-01-30 23:31:57 +00:00
parent 747da97bd1
commit d1b34654b8
4 changed files with 17 additions and 7 deletions

View File

@@ -1,5 +1,9 @@
# Nmap Changelog ($Id$); -*-text-*-
o [NSE] Fixed a bug which caused some NSE scripts to fail, due to the
absence of the NSE SCRIPT_NAME environment variable when the scripts
are loaded. Michael Pattrick reported the problem. [Djalal]
o Fixed some inconsistencies in nmap-os-db reported by Xavier Sudre
from netVigilance.

View File

@@ -1252,6 +1252,8 @@ action refer to <xref linkend="nse-tutorial-action"/>.
<literal>"prerule"</literal>, <literal>"hostrule"</literal>,
<literal>"portrule"</literal> or
<literal>"postrule"</literal>.
This variable is only available after the evaluation of
the rule functions.
</para>
</listitem>
</varlistentry>

View File

@@ -303,6 +303,7 @@ do
local script_type = assert(NSE_SCRIPT_RULES[rule]);
if not self[rule] then return nil end -- No rule for this script?
local file_closure = self.file_closure;
-- Rebuild the environment for the running thread.
local env = {
SCRIPT_PATH = self.filename,
SCRIPT_NAME = self.short_basename,
@@ -366,10 +367,15 @@ do
"Warning: Loading '%s' -- the recommended file extension is '.nse'.",
filename);
end
local basename = match(filename, "[/\\]([^/\\]-)$") or filename;
local short_basename = match(filename, "[/\\]([^/\\]-)%.nse$") or
match(filename, "[/\\]([^/\\]-)%.[^.]*$") or
filename;
local file_closure = assert(loadfile(filename));
-- Give the closure its own environment, with global access
local env = {
filename = filename,
SCRIPT_PATH = filename,
SCRIPT_NAME = short_basename,
dependencies = {},
};
setmetatable(env, {__index = _G});
@@ -412,11 +418,9 @@ do
-- Return the script
local script = {
filename = filename,
basename = match(filename, "[/\\]([^/\\]-)$") or filename,
short_basename = match(filename, "[/\\]([^/\\]-)%.nse$") or
match(filename, "[/\\]([^/\\]-)%.[^.]*$") or
filename,
id = match(filename, "^.-[/\\]([^\\/]-)%.nse$") or filename,
basename = basename,
short_basename = short_basename,
id = match(filename, "^.-[/\\]([^\\/]-)%.nse$") or short_basename,
file_closure = file_closure,
prerule = prerule,
hostrule = hostrule,

View File

@@ -51,7 +51,7 @@ else
portrule = function() return false end
action = function() end
stdnse.print_debug( 3, "Skipping %s script because OpenSSL is missing.",
filename)
SCRIPT_NAME)
return;
end