Nmap Development mailing list archives

Re: Completed Lua 5.3 upgrade!


From: Patrick Donnelly <batrick () batbytes com>
Date: Sun, 17 Jul 2016 12:11:56 -0400

On Sun, Jul 17, 2016 at 1:02 AM, Daniel Miller <bonsaiviking () gmail com> wrote:
Instead, I've pushed r36000, a change that adds a utility function
nseU_checkinteger. This function works a bit like luaL_checkinteger when
LUA_FLOORN2I is set to 1: it checks that the given index is a number, then
does a floor operation on that number before calling lua_numbertointeger to
convert it to an int (which is what lua_Integer is probably set to in most
cases). The other change involved is using signed integer timeouts instead
of unsigned, since the nsock operations all take signed values anyway. This
will help avoid integer overflow problems.

I think this function should be used in most places in the NSE libraries
where we were previously using luaL_checkinteger.  I also suspect it could
be used for lua_tointeger in lots of places, too, but I would appreciate
your input.

I wanted to avoid these conversions if possible. However, a utility
function keeping the old behavior is okay in some places (maybe not
everywhere?).

I would recommend nseU_checkinteger return a lua_Integer which can be
narrowed/cast as necessary by the caller. Also, use a cast instead of
floor as it makes the code consistent with Lua 5.2:

https://www.lua.org/source/5.2/llimits.h.html#lua_number2integer

-- 
Patrick Donnelly
_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/


Current thread: