From e03dcf3d8a7d137c2bed1ece810f2132d363b165 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 31 Dec 2012 19:06:33 +0000 Subject: [PATCH] Do a connect on rpc-grind UDP sockets to invoke socket_lock. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This connect should be side effect–free except for calling socket_lock, which prevents the creation of an excessive number of sockets. Not using the lock was causing "Too many open files" errors. We should have a cleaner general solution for this, and not require scripts to "connect" their unconnected UDP sockets. I seem to remember that there was a good reason for not enforcing the lock on socket creation, but only on connect, as we do. http://seclists.org/nmap-dev/2012/q4/435 --- nselib/rpc.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nselib/rpc.lua b/nselib/rpc.lua index cb389a7ae..8d26f108e 100644 --- a/nselib/rpc.lua +++ b/nselib/rpc.lua @@ -187,11 +187,15 @@ Comm = { local resvport = math.random(1, 1024) socket = nmap.new_socket("udp") status, err = socket:bind(nil, resvport) - if status then break end - socket:close() + if status then + status, err = socket:connect(host, port) + if status or err == "TIMEOUT" then break end + socket:close() + end end else socket = nmap.new_socket("udp") + status, err = socket:connect(host, port) end end if (not(status)) then