Nmap Development mailing list archives

Re: Question on NSE script output


From: David Fifield <david () bamsoftware com>
Date: Fri, 5 Jun 2009 22:37:04 -0600

On Sat, Jun 06, 2009 at 12:03:35AM -0400, Sina Bahram wrote:
Unless if I did it wrong, you can't actually do this:

                return host.ip .. " Anonymous FTP login allowed"
 
Let me preface with, I'm a programmer, but not a LUA one.

Here's what I've discovered.

If you are printing something, then unless if you have parentheses around
it, you can't inline concat a string.  Even if you assign it to a local
variable first, then pass the variable to the print.  Probably because it
does expansion at that point, just like lisp or something.

That is a separate issue. print is a function, not a keyword like
return. Function calls normally require parentheses around the
arguments. The exception to this rule is if there is only one argument,
and it is a literal string or a table constructor. So you can do
        print(x)
        print "Hello"
But not
        print x
        print "Hello" .. " world"
See http://www.lua.org/manual/5.1/manual.html#2.5.8

Since we're returning a string, not printing it ... I'm not sure if the
print that eventually gets called has parentheses around it; thus, when I
tried to do the line of code above, almost exactly what you wrote as your
suggestion in your email, I got the same error as if I had done a print with
a string being concatted without parentheses around it.

Does this make sense?

No, expression is evaluated and converted to a string before the return.
Whatever error message you see must be cause by something else.

I don't know why the line of code above doesn't work for you. I copied
it directly from the script after testing the modification. Can you copy
in the error message you see? A return statement must be the last thing
in a block, so if you moved the return, it may not work.

David Fifield

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: