mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Use std::multiset to keep script outputs in order instead of sorting.
This commit is contained in:
@@ -133,9 +133,10 @@ void Target::Recycle() {
|
||||
Target::~Target() {
|
||||
FreeInternal();
|
||||
#ifndef NOLUA
|
||||
while (!scriptResults.empty()) {
|
||||
scriptResults.front().clear();
|
||||
scriptResults.pop_front();
|
||||
for (ScriptResults::iterator it = scriptResults.begin();
|
||||
it != scriptResults.end(); it++) {
|
||||
ScriptResult sr = *it;
|
||||
sr.clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
16
nmap.cc
16
nmap.cc
@@ -2026,10 +2026,12 @@ int nmap_main(int argc, char *argv[]) {
|
||||
script_scan_results = get_script_scan_results_obj();
|
||||
script_scan(Targets, SCRIPT_PRE_SCAN);
|
||||
printscriptresults(script_scan_results, SCRIPT_PRE_SCAN);
|
||||
while (!script_scan_results->empty()) {
|
||||
script_scan_results->front().clear();
|
||||
script_scan_results->pop_front();
|
||||
for (ScriptResults::iterator it = script_scan_results->begin();
|
||||
it != script_scan_results->end(); it++) {
|
||||
ScriptResult sr = *it;
|
||||
sr.clear();
|
||||
}
|
||||
script_scan_results->clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2280,10 +2282,12 @@ int nmap_main(int argc, char *argv[]) {
|
||||
if (o.script) {
|
||||
script_scan(Targets, SCRIPT_POST_SCAN);
|
||||
printscriptresults(script_scan_results, SCRIPT_POST_SCAN);
|
||||
while (!script_scan_results->empty()) {
|
||||
script_scan_results->front().clear();
|
||||
script_scan_results->pop_front();
|
||||
for (ScriptResults::iterator it = script_scan_results->begin();
|
||||
it != script_scan_results->end(); it++) {
|
||||
ScriptResult sr = *it;
|
||||
sr.clear();
|
||||
}
|
||||
script_scan_results->clear();
|
||||
delete new_targets;
|
||||
new_targets = NULL;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ static int script_set_output (lua_State *L)
|
||||
lua_len(L, 3);
|
||||
sr.set_output_str(luaL_checkstring(L, 3), luaL_checkinteger(L,-1));
|
||||
}
|
||||
script_scan_results.push_back(sr);
|
||||
script_scan_results.insert(sr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ static int host_set_output (lua_State *L)
|
||||
lua_len(L, 4);
|
||||
sr.set_output_str(luaL_checkstring(L, 4), luaL_checkinteger(L,-1));
|
||||
}
|
||||
target->scriptResults.push_back(sr);
|
||||
target->scriptResults.insert(sr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define NMAP_LUA_H
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "nse_lua.h"
|
||||
@@ -30,9 +30,12 @@ class ScriptResult
|
||||
void set_id (const char *);
|
||||
const char *get_id (void) const;
|
||||
void write_xml() const;
|
||||
bool operator<(ScriptResult const &b) const {
|
||||
return this->id.compare(b.id) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::list<ScriptResult> ScriptResults;
|
||||
typedef std::multiset<ScriptResult> ScriptResults;
|
||||
|
||||
/* Call this to get a ScriptResults object which can be
|
||||
* used to store Pre-Scan and Post-Scan script Results */
|
||||
|
||||
10
output.cc
10
output.cc
@@ -446,12 +446,6 @@ std::string protect_xml(const std::string s) {
|
||||
return r;
|
||||
}
|
||||
|
||||
/* This is a helper function to determine the ordering of the script results
|
||||
based on their id. */
|
||||
static bool scriptid_lessthan(const ScriptResult &a, const ScriptResult &b) {
|
||||
return strcmp(a.get_id(), b.get_id()) < 0;
|
||||
}
|
||||
|
||||
static char *formatScriptOutput(const ScriptResult &sr) {
|
||||
std::vector<std::string> lines;
|
||||
|
||||
@@ -810,8 +804,6 @@ void printportoutput(Target *currenths, PortList *plist) {
|
||||
#ifndef NOLUA
|
||||
if (o.script) {
|
||||
ScriptResults::const_iterator ssr_iter;
|
||||
//Sort the results before outputting them on the screen
|
||||
current->scriptResults.sort(scriptid_lessthan);
|
||||
for (ssr_iter = current->scriptResults.begin();
|
||||
ssr_iter != current->scriptResults.end(); ssr_iter++) {
|
||||
ssr_iter->write_xml();
|
||||
@@ -2223,7 +2215,6 @@ void printscriptresults(ScriptResults *scriptResults, stype scantype) {
|
||||
char *script_output;
|
||||
|
||||
if (scriptResults->size() > 0) {
|
||||
scriptResults->sort(scriptid_lessthan);
|
||||
if (scantype == SCRIPT_PRE_SCAN) {
|
||||
xml_start_tag("prescript");
|
||||
log_write(LOG_PLAIN, "Pre-scan script results:\n");
|
||||
@@ -2248,7 +2239,6 @@ void printhostscriptresults(Target *currenths) {
|
||||
char *script_output;
|
||||
|
||||
if (currenths->scriptResults.size() > 0) {
|
||||
currenths->scriptResults.sort(scriptid_lessthan);
|
||||
xml_start_tag("hostscript");
|
||||
log_write(LOG_PLAIN, "\nHost script results:\n");
|
||||
for (iter = currenths->scriptResults.begin();
|
||||
|
||||
12
portlist.cc
12
portlist.cc
@@ -116,10 +116,12 @@ void Port::freeService(bool del_service) {
|
||||
void Port::freeScriptResults(void)
|
||||
{
|
||||
#ifndef NOLUA
|
||||
while (!scriptResults.empty()) {
|
||||
scriptResults.front().clear();
|
||||
scriptResults.pop_front();
|
||||
}
|
||||
for (ScriptResults::iterator it = scriptResults.begin();
|
||||
it != scriptResults.end(); it++) {
|
||||
ScriptResult sr = *it;
|
||||
sr.clear();
|
||||
}
|
||||
scriptResults.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -377,7 +379,7 @@ void PortList::addScriptResult(u16 portno, int protocol, const ScriptResult& sr)
|
||||
|
||||
port = createPort(portno, protocol);
|
||||
|
||||
port->scriptResults.push_back(sr);
|
||||
port->scriptResults.insert(sr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user