1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-22 15:39:03 +00:00

NSE nsock event handling improvements

If an event is canceled, report it to the waiting thread as an error.
Previous behavior left a waiting thread waiting forever, so NSE never
stopped.

If the event is killed, that means Nsock is being shut down, so this is
coming from the garbage collection handler and we don't want to restore
anything. Just return instead.
This commit is contained in:
dmiller
2022-01-04 18:10:44 +00:00
parent 08d50ed318
commit 026cd801d7

View File

@@ -334,8 +334,8 @@ static void status (lua_State *L, enum nse_status status)
nse_restore(L, 1);
break;
case NSE_STATUS_KILL:
return;
case NSE_STATUS_CANCELLED:
return; /* do nothing! */
case NSE_STATUS_EOF:
case NSE_STATUS_ERROR:
case NSE_STATUS_TIMEOUT:
@@ -356,6 +356,8 @@ static void callback (nsock_pool nsp, nsock_event nse, void *ud)
{
nse_nsock_udata *nu = (nse_nsock_udata *) ud;
lua_State *L = nu->thread;
if (nse_status(nse) == NSE_STATUS_KILL)
return;
assert(nse_type(nse) != NSE_TYPE_READ);
if (lua_status(L) == LUA_OK && nse_status(nse) == NSE_STATUS_ERROR) {
// Sometimes Nsock fails immediately and callback is called before
@@ -790,6 +792,8 @@ static int sleep_destructor (lua_State *L)
static void sleep_callback (nsock_pool nsp, nsock_event nse, void *ud)
{
lua_State *L = (lua_State *) ud;
if (nse_status(nse) == NSE_STATUS_KILL)
return;
assert(lua_status(L) == LUA_YIELD);
assert(nse_status(nse) == NSE_STATUS_SUCCESS);
nse_restore(L, 0);