mirror of
https://github.com/nmap/nmap.git
synced 2025-12-11 10:19:03 +00:00
Previously, process_mainloop() assumed that there can occur only one event for l_nsock_loop(). This is obviously wrong. This caused that some lua threads wakeups (when multiple events happend for one nsock_loop) were delayed. They were handled but way after real events happened. This patch changes the handing of events. Now we execute every lua thread which is in running_scripts(). I hope that every thread will be scheduled in nsock and removed from running_scripts and added to waiting_scripts.
This commit is contained in:
93
nse_main.cc
93
nse_main.cc
@@ -286,55 +286,54 @@ int process_mainloop(lua_State* l) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(running_scripts.begin() == running_scripts.end())
|
while(running_scripts.begin() != running_scripts.end()){
|
||||||
continue;
|
current = *(running_scripts.begin());
|
||||||
|
|
||||||
current = *(running_scripts.begin());
|
if (current.rr->host->timedOut(&now))
|
||||||
|
state = LUA_ERRRUN;
|
||||||
if (current.rr->host->timedOut(&now))
|
else
|
||||||
state = LUA_ERRRUN;
|
state = lua_resume(current.thread, current.resume_arguments);
|
||||||
else
|
|
||||||
state = lua_resume(current.thread, current.resume_arguments);
|
if(state == LUA_YIELD) {
|
||||||
|
// this script has performed a network io operation
|
||||||
if(state == LUA_YIELD) {
|
// we put it in the waiting
|
||||||
// this script has performed a network io operation
|
// when the network io operation has completed,
|
||||||
// we put it in the waiting
|
// a callback from the nsock library will put the
|
||||||
// when the network io operation has completed,
|
// script back into the running state
|
||||||
// a callback from the nsock library will put the
|
|
||||||
// script back into the running state
|
waiting_scripts.push_back(current);
|
||||||
|
running_scripts.pop_front();
|
||||||
waiting_scripts.push_back(current);
|
} else if( state == 0) {
|
||||||
running_scripts.pop_front();
|
// this script has finished
|
||||||
} else if( state == 0) {
|
// we first check if it produced output
|
||||||
// this script has finished
|
// then we release the thread and remove it from the
|
||||||
// we first check if it produced output
|
// running_scripts list
|
||||||
// then we release the thread and remove it from the
|
|
||||||
// running_scripts list
|
if(lua_isstring (current.thread, -1)) {
|
||||||
|
SCRIPT_ENGINE_TRY(process_getScriptId(current.thread, &ssr));
|
||||||
if(lua_isstring (current.thread, -1)) {
|
ssr.output = nse_printable
|
||||||
SCRIPT_ENGINE_TRY(process_getScriptId(current.thread, &ssr));
|
(lua_tostring(current.thread, -1), lua_objlen(current.thread, -1));
|
||||||
ssr.output = nse_printable
|
if(current.rr->type == 0) {
|
||||||
(lua_tostring(current.thread, -1), lua_objlen(current.thread, -1));
|
current.rr->host->scriptResults.push_back(ssr);
|
||||||
if(current.rr->type == 0) {
|
} else if(current.rr->type == 1) {
|
||||||
current.rr->host->scriptResults.push_back(ssr);
|
current.rr->port->scriptResults.push_back(ssr);
|
||||||
} else if(current.rr->type == 1) {
|
current.rr->host->ports.numscriptresults++;
|
||||||
current.rr->port->scriptResults.push_back(ssr);
|
}
|
||||||
current.rr->host->ports.numscriptresults++;
|
lua_pop(current.thread, 2);
|
||||||
}
|
}
|
||||||
lua_pop(current.thread, 2);
|
|
||||||
|
SCRIPT_ENGINE_TRY(process_finalize(l, current.registry_idx));
|
||||||
|
SCRIPT_ENGINE_TRY(lua_gc(l, LUA_GCCOLLECT, 0));
|
||||||
|
} else {
|
||||||
|
// this script returned because of an error
|
||||||
|
// print the failing reason if the verbose level is high enough
|
||||||
|
SCRIPT_ENGINE_DEBUGGING(
|
||||||
|
const char* errmsg = lua_tostring(current.thread, -1);
|
||||||
|
log_write(LOG_STDOUT, "%s: %s\n", SCRIPT_ENGINE, errmsg);
|
||||||
|
)
|
||||||
|
SCRIPT_ENGINE_TRY(process_finalize(l, current.registry_idx));
|
||||||
}
|
}
|
||||||
|
} // while
|
||||||
SCRIPT_ENGINE_TRY(process_finalize(l, current.registry_idx));
|
|
||||||
SCRIPT_ENGINE_TRY(lua_gc(l, LUA_GCCOLLECT, 0));
|
|
||||||
} else {
|
|
||||||
// this script returned because of an error
|
|
||||||
// print the failing reason if the verbose level is high enough
|
|
||||||
SCRIPT_ENGINE_DEBUGGING(
|
|
||||||
const char* errmsg = lua_tostring(current.thread, -1);
|
|
||||||
log_write(LOG_STDOUT, "%s: %s\n", SCRIPT_ENGINE, errmsg);
|
|
||||||
)
|
|
||||||
SCRIPT_ENGINE_TRY(process_finalize(l, current.registry_idx));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.endTask(NULL, NULL);
|
progress.endTask(NULL, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user