mirror of
https://github.com/nmap/nmap.git
synced 2026-01-18 12:19:02 +00:00
[NSE] This patch is related to the change to eliminate the reliance on
GC for collecting socket locks [1]. If a thread does not close any sockets it creates, and then returns (or errors), the thread and sockets will keep their "lock" until garbage collected. This would be the same situation as before in this particular case (reliance on GC). To fix this, I have changed the socket unlock system to close all the sockets of a thread not yielded and remove its "lock". [1] http://seclists.org/nmap-dev/2009/q2/0624.html
This commit is contained in:
23
nse_nsock.cc
23
nse_nsock.cc
@@ -320,16 +320,29 @@ static void socket_unlock(lua_State * L)
|
||||
{
|
||||
unsigned open = 0;
|
||||
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2) != 0) /* for each socket */
|
||||
if (lua_status(lua_tothread(L, -2)) == LUA_YIELD)
|
||||
{
|
||||
lua_pop(L, 1); /* pop garbage boolean */
|
||||
if (((struct l_nsock_udata *) lua_touserdata(L, -1))->nsiod != NULL)
|
||||
open++;
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2) != 0) /* for each socket */
|
||||
{
|
||||
lua_pop(L, 1); /* pop garbage boolean */
|
||||
if (((struct l_nsock_udata *) lua_touserdata(L, -1))->nsiod != NULL)
|
||||
open++;
|
||||
}
|
||||
}
|
||||
|
||||
if (open == 0) /* thread has no open sockets? */
|
||||
{
|
||||
/* close all of its sockets */
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2) != 0) /* for each socket */
|
||||
{
|
||||
lua_pop(L, 1); /* pop garbage boolean */
|
||||
lua_getfield(L, -1, "close");
|
||||
lua_pushvalue(L, -2);
|
||||
lua_call(L, 1, 0);
|
||||
}
|
||||
|
||||
lua_pushvalue(L, -2); /* thread key */
|
||||
lua_pushnil(L);
|
||||
lua_rawset(L, top+1); /* THREADS_SOCKETS */
|
||||
|
||||
Reference in New Issue
Block a user