Blame SOURCES/nmap-6.40-nsock_param.patch

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