diff --git a/CHANGES b/CHANGES index ff2e8c27..837a32fe 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ DD mmm YYYY - X.Y.Z (To be released) ------------------------------------ + * Extanded Lua support to include version 5.3 + [Issue #837, #762, #814 - Athmane Madjoudj and ModSecurity team] * mlogc: Allow user to choose between TLS versions (TLSProtocol option introduced). [Issue #881 - Ishwor Gurung] diff --git a/apache2/msc_lua.c b/apache2/msc_lua.c index 58206a75..51be1745 100644 --- a/apache2/msc_lua.c +++ b/apache2/msc_lua.c @@ -112,7 +112,7 @@ char *lua_compile(msc_script **script, const char *filename, apr_pool_t *pool) { dump.parts = apr_array_make(pool, 128, sizeof(msc_script_part *)); #if LUA_VERSION_NUM >= 503 - lua_dump(L, dump_writer, &dump, 1); + lua_dump(L, dump_writer, &dump, 0); #else lua_dump(L, dump_writer, &dump); #endif @@ -420,23 +420,32 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul time_before = apr_time_now(); #ifdef CACHE_LUA + L = msr->L; rc = lua_gettop(L); if(rc) lua_pop(L, rc); + #else + /* Create new state. */ -#if LUA_VERSION_NUM > 501 +#if LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 || LUA_VERSION_NUM == 501 L = luaL_newstate(); -#else +#elif LUA_VERSION_NUM == 500 L = lua_open(); +#else +#error We are only tested under Lua 5.0, 5.1, 5.2, or 5.3. #endif luaL_openlibs(L); + #endif if(L == NULL) return -1; + luaL_newmetatable(L, "luaL_msc"); + lua_newtable(L); + /* Associate msr with the state. */ lua_pushlightuserdata(L, (void *)msr); lua_setglobal(L, "__msr"); @@ -448,13 +457,16 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul } /* Register functions. */ -#if LUA_VERSION_NUM > 501 - luaL_setfuncs(L,mylib,0); - lua_setglobal(L,"m"); -#else +#if LUA_VERSION_NUM == 500 || LUA_VERSION_NUM == 501 luaL_register(L, "m", mylib); +#elif LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 + luaL_setfuncs(L, mylib, 0); +#else +#error We are only tested under Lua 5.0, 5.1, 5.2, or 5.3. #endif + lua_setglobal(L, "m"); + rc = lua_restore(L, script); if (rc) { *error_msg = apr_psprintf(msr->mp, "Lua: Failed to restore script with %i.", rc); diff --git a/build/find_lua.m4 b/build/find_lua.m4 index b8628011..acb903e5 100644 --- a/build/find_lua.m4 +++ b/build/find_lua.m4 @@ -16,7 +16,7 @@ LUA_CPPFLAGS="" LUA_LDADD="" LUA_LDFLAGS="" LUA_CONFIG=${PKG_CONFIG} -LUA_PKGNAMES="lua5.1 lua-5.1 lua_5.1 lua-51 lua_51 lua51 lua5 lua" +LUA_PKGNAMES="lua5.1 lua-5.1 lua_5.1 lua-51 lua_51 lua51 lua5 lua lua5.2 lua-5.2 lua_5.2 lua-52 lua_52 lua52 lua5.3 lua-5.3 lua_5.3 lua-53 lua_53 lua53 " LUA_SONAMES="so la sl dll dylib a" AC_ARG_WITH(