Skip to content

Commit 05bcafd

Browse files
author
Felipe Zimmerle
committed
Extends Lua implementation to support Lua 5.3
1 parent 74558b4 commit 05bcafd

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
DD mmm YYYY - X.Y.Z (To be released)
22
------------------------------------
33

4+
* Extanded Lua support to include version 5.3
5+
[Issue #837, #762, #814 - Athmane Madjoudj and ModSecurity team]
46
* mlogc: Allow user to choose between TLS versions (TLSProtocol option
57
introduced).
68
[Issue #881 - Ishwor Gurung]

apache2/msc_lua.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ char *lua_compile(msc_script **script, const char *filename, apr_pool_t *pool) {
112112
dump.parts = apr_array_make(pool, 128, sizeof(msc_script_part *));
113113

114114
#if LUA_VERSION_NUM >= 503
115-
lua_dump(L, dump_writer, &dump, 1);
115+
lua_dump(L, dump_writer, &dump, 0);
116116
#else
117117
lua_dump(L, dump_writer, &dump);
118118
#endif
@@ -420,23 +420,32 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul
420420
time_before = apr_time_now();
421421

422422
#ifdef CACHE_LUA
423+
423424
L = msr->L;
424425
rc = lua_gettop(L);
425426
if(rc)
426427
lua_pop(L, rc);
428+
427429
#else
430+
428431
/* Create new state. */
429-
#if LUA_VERSION_NUM > 501
432+
#if LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 || LUA_VERSION_NUM == 501
430433
L = luaL_newstate();
431-
#else
434+
#elif LUA_VERSION_NUM == 500
432435
L = lua_open();
436+
#else
437+
#error We are only tested under Lua 5.0, 5.1, 5.2, or 5.3.
433438
#endif
434439
luaL_openlibs(L);
440+
435441
#endif
436442

437443
if(L == NULL)
438444
return -1;
439445

446+
luaL_newmetatable(L, "luaL_msc");
447+
lua_newtable(L);
448+
440449
/* Associate msr with the state. */
441450
lua_pushlightuserdata(L, (void *)msr);
442451
lua_setglobal(L, "__msr");
@@ -448,13 +457,16 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul
448457
}
449458

450459
/* Register functions. */
451-
#if LUA_VERSION_NUM > 501
452-
luaL_setfuncs(L,mylib,0);
453-
lua_setglobal(L,"m");
454-
#else
460+
#if LUA_VERSION_NUM == 500 || LUA_VERSION_NUM == 501
455461
luaL_register(L, "m", mylib);
462+
#elif LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503
463+
luaL_setfuncs(L, mylib, 0);
464+
#else
465+
#error We are only tested under Lua 5.0, 5.1, 5.2, or 5.3.
456466
#endif
457467

468+
lua_setglobal(L, "m");
469+
458470
rc = lua_restore(L, script);
459471
if (rc) {
460472
*error_msg = apr_psprintf(msr->mp, "Lua: Failed to restore script with %i.", rc);

build/find_lua.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LUA_CPPFLAGS=""
1616
LUA_LDADD=""
1717
LUA_LDFLAGS=""
1818
LUA_CONFIG=${PKG_CONFIG}
19-
LUA_PKGNAMES="lua5.1 lua-5.1 lua_5.1 lua-51 lua_51 lua51 lua5 lua"
19+
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 "
2020
LUA_SONAMES="so la sl dll dylib a"
2121
2222
AC_ARG_WITH(

0 commit comments

Comments
 (0)