1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Hide error traceback for nmap.new_try() handled exceptions. Fixes #2463

This commit is contained in:
dmiller
2022-06-29 20:40:30 +00:00
parent 51139a637f
commit 07bc658c4a
3 changed files with 22 additions and 2 deletions

View File

@@ -1,5 +1,10 @@
#Nmap Changelog ($Id$); -*-text-*- #Nmap Changelog ($Id$); -*-text-*-
o [NSE][GH#2463] NSE "exception handling" with nmap.new_try() will no longer
result in a stack traceback in debug output nor a "ERROR: script execution
failed" message in script output, since the intended behavior has always been
to end the script immediately without output. [Daniel Miller]
o Upgrade libssh2 to 1.10.0. o Upgrade libssh2 to 1.10.0.
o [NSE][GH#2496] Fix newtargets support: since Nmap 7.92, scripts could not add o [NSE][GH#2496] Fix newtargets support: since Nmap 7.92, scripts could not add

View File

@@ -523,7 +523,15 @@ do
self.action_started = true self.action_started = true
return self:resume(timeouts); return self:resume(timeouts);
elseif not ok then elseif not ok then
-- Extend this to create new types of errors with custom handling.
-- nmap.new_try does equivalent of: error({errtype="nmap.new_try", message="TIMEOUT"})
if type(r1) == "table" and r1.errtype == "nmap.new_try" then
-- nmap.new_try "exception" is closing the script
if debugging() > 0 then if debugging() > 0 then
self:d("Finished %THREAD_AGAINST. Reason: %s\n", r1.message);
end
r1 = r1.message
elseif debugging() > 0 then
self:d("%THREAD_AGAINST threw an error!\n%s\n", traceback(self.co, tostring(r1))); self:d("%THREAD_AGAINST threw an error!\n%s\n", traceback(self.co, tostring(r1)));
else else
self:set_output("ERROR: Script execution failed (use -d to debug)"); self:set_output("ERROR: Script execution failed (use -d to debug)");

View File

@@ -624,7 +624,14 @@ static int l_log_write (lua_State *L)
static int finalize_cleanup (lua_State *L, int status, lua_KContext ctx) static int finalize_cleanup (lua_State *L, int status, lua_KContext ctx)
{ {
lua_settop(L, 2); lua_settop(L, 2); // top of stack: error message
lua_createtable(L, 0, 2); // error object table
lua_pushliteral(L, "errtype");
lua_pushliteral(L, "nmap.new_try");
lua_rawset(L, -3);
lua_pushliteral(L, "message"); // stack: err(string), err(table), "message"
lua_rotate(L, -3, -1); // stack: err(table), "message", err(string)
lua_rawset(L, -3);
return lua_error(L); return lua_error(L);
} }