mirror of
https://github.com/nmap/nmap.git
synced 2026-05-13 08:46:45 +00:00
Avoid crashing when Nsock connect calls the callback immediately due to parameter errors
This commit is contained in:
parent
374d0a1392
commit
0577e3bb1e
2 changed files with 21 additions and 4 deletions
12
nse_nsock.cc
12
nse_nsock.cc
|
|
@ -350,6 +350,15 @@ 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 (lua_status(L) == LUA_OK && nse_status(nse) == NSE_STATUS_ERROR) {
|
||||
// Sometimes Nsock fails immediately and callback is called before
|
||||
// l_connect has a chance to yield. TODO: Figure out how to return an error
|
||||
// to the calling thread without falling into an infinite loop somewhere.
|
||||
// http://seclists.org/nmap-dev/2016/q1/201
|
||||
trace(nse_iod(nse), nu->action, nu->direction);
|
||||
nsock_iod_delete(nu->nsiod, NSOCK_PENDING_NOTIFY);
|
||||
luaL_error(L, "Nsock immediate error");
|
||||
}
|
||||
assert(lua_status(L) == LUA_YIELD);
|
||||
trace(nse_iod(nse), nu->action, nu->direction);
|
||||
status(L, nse_status(nse));
|
||||
|
|
@ -515,6 +524,9 @@ static int l_connect (lua_State *L)
|
|||
}
|
||||
|
||||
nu->af = dest->ai_addr->sa_family;
|
||||
nu->thread = L;
|
||||
nu->action = "PRECONNECT";
|
||||
nu->direction = TO;
|
||||
|
||||
switch (what)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue