|
|
a41e58 |
diff -up nmap-6.40/nse_nsock.cc.sfdc02129088 nmap-6.40/nse_nsock.cc
|
|
|
a41e58 |
--- nmap-6.40/nse_nsock.cc.sfdc02129088 2018-07-03 11:24:38.000000000 +0200
|
|
|
a41e58 |
+++ nmap-6.40/nse_nsock.cc 2018-07-03 11:40:03.000000000 +0200
|
|
|
a41e58 |
@@ -351,6 +351,15 @@ static void callback (nsock_pool nsp, ns
|
|
|
a41e58 |
{
|
|
|
a41e58 |
nse_nsock_udata *nu = (nse_nsock_udata *) ud;
|
|
|
a41e58 |
lua_State *L = nu->thread;
|
|
|
a41e58 |
+ if (lua_status(L) == LUA_OK && nse_status(nse) == NSE_STATUS_ERROR) {
|
|
|
a41e58 |
+ // Sometimes Nsock fails immediately and callback is called before
|
|
|
a41e58 |
+ // l_connect has a chance to yield. TODO: Figure out how to return an error
|
|
|
a41e58 |
+ // to the calling thread without falling into an infinite loop somewhere.
|
|
|
a41e58 |
+ // http://seclists.org/nmap-dev/2016/q1/201
|
|
|
a41e58 |
+ trace(nse_iod(nse), nu->action, nu->direction);
|
|
|
a41e58 |
+ nsi_delete(nu->nsiod, NSOCK_PENDING_NOTIFY);
|
|
|
a41e58 |
+ luaL_error(L, "Nsock immediate error");
|
|
|
a41e58 |
+ }
|
|
|
a41e58 |
assert(lua_status(L) == LUA_YIELD);
|
|
|
a41e58 |
trace(nse_iod(nse), nu->action, nu->direction);
|
|
|
a41e58 |
status(L, nse_status(nse));
|
|
|
a41e58 |
@@ -505,6 +514,9 @@ static int l_connect (lua_State *L)
|
|
|
a41e58 |
}
|
|
|
a41e58 |
|
|
|
a41e58 |
nu->af = dest->ai_addr->sa_family;
|
|
|
a41e58 |
+ nu->thread = L;
|
|
|
a41e58 |
+ nu->action = "PRECONNECT";
|
|
|
a41e58 |
+ nu->direction = TO;
|
|
|
a41e58 |
|
|
|
a41e58 |
switch (what)
|
|
|
a41e58 |
{
|