[blfs-dev] nmap-6.47 fixes to build with system lua-5.3.0

Fernando de Oliveira famobr at yahoo.com.br
Fri Jan 23 13:10:59 PST 2015


I tried latest development svn code:

svn co https://svn.nmap.org/nmap nmap-2015.01.22

No difference, with respect of lua's problems.

All fixes, sed' are written in the order that the problems appeared. I
separated some sed -e ... -e ... -i ..into

sed ...
...
sed ...

even when the input file is the same, so that it reproduces what I tried
to do and all the steps. After each step, I ran

make clean
time ./configure --prefix=/usr 2>&1 | tee ../nmap-6.47-configure.log
time make -j1 2>&1 | tee ../nmap-6.47-make.log

Was not making any progress, then discovered that it was taking some
headers from the system and others from the included liblua directory:

Fix 1:

rm -rf liblua

Fix2:

sed -i 's/luaL_checkint/(int)&eger/' nse_main.cc

Fix3

sed -i 's/lua_CFunction/lua_KFunction/' nse_main.cc

This is a very problematic one and I am not sure about the consequences
or correctness. Fact is that there was a message of invalid conversion
from lua_CFunction to lua_KFunction, after I used Fix3.

Fix4:

sed -e 's/(uint16_t) luaL_checkint/(lua_Unsigned)luaL_checkinteger/' \
    -i nse_utility.cc

I couldn't find any type completely equivalent to uint16, searching in
the internet, some comments indicated that this would be the best bet.

Fix5:

sed -e 's/luaL_checkint/(int)&eger/' -i nse_nsock.cc

Fix6:

sed -e 's/lua_getctx(L, NULL)/lua_status(L)/' -i nse_nsock.cc

This one completes the compilation of nsock.o. But again, I can't be
sure. Problem is that lua_getctx was removed, so, I made a guess,
probably wrong, to replace it.

The analysis of the error need some Fix6 is similar to the one made near
the end of the post, after the last error message.

If this fix is modified, perhaps some of the following errors might not
appear.

Fix7:

sed -i 's/== 502/>= 502/' nse_fs.cc

Fix8:

sed -i  nse_nmaplib.cc \
-e 's/(unsigned short) luaL_checkint/(lua_Unsigned)luaL_checkinteger/'

Here again, could not find lus_Unsigned_short.

Configure takes            0.22 SBU
Make after last Fix8 takes 0.38 SBU

Now, nse_nmaplib.cc fails to build with (edited to avoid breaking lines)
message (the warning might be due to wrong Fix3):

{{{
nse_nsock.cc: In function ‘int l_bind(lua_State*)’:
nse_nsock.cc:790:31: warning: value computed is not used [-Wunused-value]
   (int)luaL_checkinteger(L, 3);
                               ^
g++ -c -I/usr/include/lua -I./libdnet-stripped/include  -I./nbase \
-I./nsock/include -DHAVE_CONFIG_H -DNMAP_NAME=\"Nmap\" \
-DNMAP_URL=\"http://nmap.org\" -DNMAP_PLATFORM=\"i686-pc-linux-gnu\" \
-DNMAPDATADIR=\"/usr/share/nmap\" -D_FORTIFY_SOURCE=2 -g -O2 -Wall \
-fno-strict-aliasing   nse_dnet.cc -o nse_dnet.o
g++ -c -I/usr/include/lua -I./libdnet-stripped/include  -I./nbase \
-I./nsock/include -DHAVE_CONFIG_H -DNMAP_NAME=\"Nmap\" \
-DNMAP_URL=\"http://nmap.org\" -DNMAP_PLATFORM=\"i686-pc-linux-gnu\" \
-DNMAPDATADIR=\"/usr/share/nmap\" -D_FORTIFY_SOURCE=2 -g -O2 -Wall \
-fno-strict-aliasing   nse_fs.cc -o nse_fs.o
g++ -c -I/usr/include/lua -I./libdnet-stripped/include  -I./nbase \
-I./nsock/include -DHAVE_CONFIG_H -DNMAP_NAME=\"Nmap\" \
-DNMAP_URL=\"http://nmap.org\" -DNMAP_PLATFORM=\"i686-pc-linux-gnu\" \
-DNMAPDATADIR=\"/usr/share/nmap\" -D_FORTIFY_SOURCE=2 -g -O2 -Wall \
-fno-strict-aliasing   nse_nmaplib.cc -o nse_nmaplib.o
nse_nmaplib.cc: In function ‘int new_try_finalize(lua_State*)’:
nse_nmaplib.cc:623:45: error: invalid conversion from ‘int
(*)(lua_State*)’ to ‘lua_KFunction {aka int (*)(lua_State*, int, int)}’
[-fpermissive]
       lua_callk(L, 0, 0, 0, finalize_cleanup);
                                             ^
In file included from nse_nmaplib.cc:3:0:
/usr/include/lua.h:270:16: note: initializing argument 5 of ‘void
lua_callk(lua_State*, int, int, lua_KContext, lua_KFunction)’
 LUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,
                ^
Makefile:107: recipe for target 'nse_nmaplib.o' failed
make[1]: *** [nse_nmaplib.o] Error 1
make[1]: Leaving directory '/home/fernando/tmp/nmap-lua/nmap-6.47'
Makefile:115: recipe for target 'all' failed
make: *** [all] Error 2
}}}

Problem here is that in lua-5.3.0, we have (in /usr/include/lua.h):

LUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,
                           lua_KContext ctx, lua_KFunction k);

While in the older one:

LUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,
                           int ctx, lua_CFunction k);

But function

new_try_finalize (lua_State *L)

uses "lua_callk" with the arguments:

lua_callk(L, 0, 0, 0, finalize_cleanup)

so that finalize_cleanup is type lua_CFunction k, whereas in the new
lua-5.3.0 it is lua_KFunction.

If I new to program in cc would probably create a function to convert
function finalize_cleanup output into a new funcion finalize_cleanupK
output or vice-versa, to fix function new_try_finalize.

This analysis can be done with problem leading to Fix6.

-- 
[]s,
Fernando


More information about the blfs-dev mailing list