mailing list archives
Re: [NSE] Catching socket errors, documentation discrepancy
From: David Fifield <david () bamsoftware com>
Date: Wed, 20 Jun 2012 20:13:29 -0700
On Mon, May 28, 2012 at 04:18:59PM -0700, David Fifield wrote:
On Wed, Sep 21, 2011 at 10:33:37PM -0500, Daniel Miller wrote:
On Wed, Sep 21, 2011 at 5:26 PM, David Fifield <david () bamsoftware com> wrote:
On Wed, Sep 21, 2011 at 05:23:25PM -0500, Daniel Miller wrote:
While working on a script, I found that the socket I/O described on
the NSE API page (http://nmap.org/book/nse-api.html) and in the nmap
library documentation (http://nmap.org/nsedoc/lib/nmap.html#send) is
not how it is currently implemented. Specifically, socket operations
are now throwing Lua errors instead of returning a false value and
an error string. Is there a current reference for how errors should
be treated? Is there a plan to change the existing documentation to
match the current implementation? I could source-dive and find how
to do it myself, but I think we should be a little more
user-friendly for script authors who take the documentation at its
Please be more specific about the socket errors that are causing Lua
errors for you. Can you show us example code?
Specifically, trying to send on an unconnected socket. There's
probably a better way to do things in general, but I'm working with
someone else's code and trying not to make sweeping changes. A minimal
test script is attached that exhibits the behavior.
You are right, it shouldn't work like that. Here is what I see:
Initiating NSE at 10:03
NSE: test threw an error!
/home/david/nmap-git/scripts/test.nse:15: socket must be connected
[C]: in function 'send'
/home/david/nmap-git/scripts/test.nse:15: in function </home/david/nmap-git/scripts/test.nse:13>
I'm attaching a patch that turns these into normal error returns. With
it, I get this.
Initiating NSE at 16:16
NSE: Finished 'test' (thread: 0x1bf3b60).
Completed NSE at 16:16, 0.00s elapsed
Pre-scan script results:
|_test: socket must be connected
The patch is mostly a mechanical replacement of
check_nsock_udata(L, 1, 1);
nse_nsock_udata *nu = check_nsock_udata(L, 1);
where the third argument to check_nsock_udata is a boolean controlling
whether the socket must be open, and NSOCK_UDATA_ENSURE_OPEN is a macro
that returns the enclosing function with an error if the socket is not
I committed this patch as r29016.
Sent through the nmap-dev mailing list
Archived at http://seclists.org/nmap-dev/