Nmap Development mailing list archives

Re: nse exceptions false or nil


From: David Fifield <david () bamsoftware com>
Date: Wed, 12 Mar 2008 12:45:15 -0600

On Wed, Mar 12, 2008 at 09:34:45AM -0800, Jaime Reza wrote:
there was a bug fix for the nse_nmaplib.cc file's
l_exc_finalize that wasn't checked into svn

Index: nse_nmaplib.cc
===================================================================
--- nse_nmaplib.cc    (revision 6128)
+++ nse_nmaplib.cc    (working copy)
@@ -460,13 +460,15 @@
 }

 static int l_exc_finalize(lua_State *l) {
-     if (lua_isnil(l, 1)) {
+     if (!lua_toboolean(l, 1)) {
+             /* false or nil. */
              lua_pushvalue(l, lua_upvalueindex(1));
              lua_call(l, 0, 0);
              lua_settop(l, 2);
              lua_error(l);
              return 0;
-     } else if(lua_toboolean(l, 1)) {
+     } else if(lua_isboolean(l, 1) && lua_toboolean(l, 1)) {
+             /* true. */
              lua_remove(l, 1);
              return lua_gettop(l);
      } else {

The latest code from svn has
static int l_exc_finalize(lua_State *l) {
    if (!lua_toboolean(l, 1)) {
        /* false or nil. */
        lua_pushvalue(l, lua_upvalueindex(1));
        lua_call(l, 0, 0);
        lua_settop(l, 2);
        lua_error(l);
        return 0;
    } else if(lua_isboolean(l, 1) && lua_toboolean(l, 1)) {
        /* true. */
        lua_remove(l, 1);
        return lua_gettop(l);
    } else {
        fatal("%s: In: %s:%i Trying to finalize a non conforming function.
Are you sure you return true on success followed by the remaining return
values and nil on failure followed by an error string?",
            SCRIPT_ENGINE, __FILE__, __LINE__);

        return 0;
    }
}

Which one is correct? the one in svn (latest sink is giving me troubles)

Hi Turinreza,

I checked in the above change in r6306. What do you mean "wasn't checked
into svn"? Please see the thread at

http://seclists.org/nmap-dev/2007/q4/0207.html

and especially

http://seclists.org/nmap-dev/2007/q4/0213.html

The reason for the change is that previously, only a nil return code
would raise an NSE exception. But many of the internal NSE functions
returned false, not nil, making it impossible to catch an exception
caused by one of them (they were "non conforming"). We decided that,
rather than modify all the internal functions to return nil instead of
false, we should just treat false the same as nil.

In short, before the patch, only nil and true were valid return values.
Now nil, false, and true are the valid return values, and anything else
is non-conforming.

What troubles are you having?

David Fifield

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


Current thread: