lua-hooks/ext/all.c in immunio-0.15.4 vs lua-hooks/ext/all.c in immunio-0.16.0
- old
+ new
@@ -2,77 +2,66 @@
* Based on Lua's all.c -- Lua core & libraries in a single file.
*/
#define luaall_c
-#define LUA_USE_POSIX
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
-#include "lua/lapi.c"
-#include "lua/lcode.c"
-#include "lua/ldebug.c"
-#include "lua/ldo.c"
-#include "lua/ldump.c"
-#include "lua/lfunc.c"
-#include "lua/lgc.c"
-#include "lua/llex.c"
-#include "lua/lmem.c"
-#include "lua/lobject.c"
-#include "lua/lopcodes.c"
-#include "lua/lparser.c"
-#include "lua/lstate.c"
-#include "lua/lstring.c"
-#include "lua/ltable.c"
-#include "lua/ltm.c"
-#include "lua/lundump.c"
-#include "lua/lvm.c"
-#include "lua/lzio.c"
-#include "lua/lauxlib.c"
-#include "lua/lbaselib.c"
-#include "lua/ldblib.c"
-#include "lua/liolib.c"
-#include "lua/lmathlib.c"
-#include "lua/loadlib.c"
-#include "lua/loslib.c"
-#include "lua/lstrlib.c"
-#include "lua/ltablib.c"
-
// Include our custom modules
-#include "bitop/bit.c"
#include "libinjection/lualib.c"
#include "luautf8/lutf8lib.c"
#include "lpeg/lptree.c"
#include "lua-cmsgpack/lua_cmsgpack.c"
#include "lua-snapshot/snapshot.c"
-// Activate the Lua modules we need and our custom ones.
-static const luaL_Reg lualibs[] = {
- {"", luaopen_base},
- {LUA_TABLIBNAME, luaopen_table},
- {LUA_STRLIBNAME, luaopen_string},
- {LUA_MATHLIBNAME, luaopen_math},
-
- // Include unsafe libs in tests
-#if defined(LUA_UNSAFE_MODE)
- {LUA_IOLIBNAME, luaopen_io},
- {LUA_OSLIBNAME, luaopen_os},
-#endif
-
+static const luaL_Reg lj_lib_load[] = {
+ // Default Lua modules
+ //
// SECURITY NOTE:
- // The following modules are unsafe according to http://lua-users.org/wiki/SandBoxes.
+ // Some of the following modules are unsafe according to http://lua-users.org/wiki/SandBoxes.
// They are loaded, but never exposed to the sandbox used to run the hook handlers.
// See lib/boot.lua for more details.
- {LUA_LOADLIBNAME, luaopen_package},
- {LUA_DBLIBNAME, luaopen_debug},
+ { "", luaopen_base },
+ { LUA_LOADLIBNAME, luaopen_package },
+ { LUA_TABLIBNAME, luaopen_table },
+ #if defined(LUA_UNSAFE_MODE)
+ { LUA_IOLIBNAME, luaopen_io },
+ { LUA_OSLIBNAME, luaopen_os },
+ #endif
+ { LUA_STRLIBNAME, luaopen_string },
+ { LUA_MATHLIBNAME, luaopen_math },
+ { LUA_DBLIBNAME, luaopen_debug },
+ { LUA_BITLIBNAME, luaopen_bit },
+ { LUA_JITLIBNAME, luaopen_jit },
// Our custom modules
{"libinjection", luaopen_libinjection},
{"utf8", luaopen_utf8},
- {"bit", luaopen_bit},
{"lpeg", luaopen_lpeg},
{LUACMSGPACK_NAME, luaopen_cmsgpack},
{"snapshot", luaopen_snapshot},
- {NULL, NULL}
+
+ { NULL, NULL }
};
-// The previous array replaces the one in linit.c.
-// If you update Lua, make sure to comment the lualibs declaration in the following file.
-#include "lua/linit.c"
+
+// In unsafe mode define these as NOPs when we build a .so
+#if !defined(LUA_UNSAFE_MODE)
+LUALIB_API int luaopen_io(lua_State *L) {
+ return 0;
+}
+LUALIB_API int luaopen_os(lua_State *L) {
+ return 0;
+}
+#endif
+
+LUALIB_API void luaL_openlibs(lua_State *L) {
+ const luaL_Reg *lib;
+ for (lib = lj_lib_load; lib->func; lib++) {
+ lua_pushcfunction(L, lib->func);
+ lua_pushstring(L, lib->name);
+ lua_call(L, 1, 0);
+ }
+}
+