static void DetectLuaFree(DetectEngineCtx *, void *);
static int g_smtp_generic_list_id = 0;
-// TODO: move to config
-static const uint64_t g_lua_alloc_limit = 500000, g_lua_instruction_limit = 500000;
-
/**
* \brief Registration function for keyword: lua
*/
#define FLAG_DATATYPE_BUFFER BIT_U32(22)
#define FLAG_ERROR_LOGGED BIT_U32(23)
+// TODO: move to config
+#define DEFAULT_LUA_ALLOC_LIMIT 500000
+#define DEFAULT_LUA_INSTRUCTION_LIMIT 500000
+
#if 0
/** \brief dump stack from lua state to screen */
void LuaDumpStack(lua_State *state)
t->alproto = lua->alproto;
t->flags = lua->flags;
- t->luastate = sb_newstate(g_lua_alloc_limit, g_lua_instruction_limit);
+ t->luastate = sb_newstate(lua->alloc_limit, lua->instruction_limit);
if (t->luastate == NULL) {
SCLogError("luastate pool depleted");
goto error;
{
int status;
- lua_State *luastate = sb_newstate(g_lua_alloc_limit, g_lua_instruction_limit);
+ lua_State *luastate = sb_newstate(ld->alloc_limit, ld->instruction_limit);
if (luastate == NULL)
return -1;
luaL_openlibs(luastate); // TODO: get sandbox config and load appropriate libs
if (lua == NULL)
goto error;
+ /* Load lua sandbox configurations */
+ intmax_t lua_alloc_limit = DEFAULT_LUA_ALLOC_LIMIT;
+ intmax_t lua_instruction_limit = DEFAULT_LUA_INSTRUCTION_LIMIT;
+ (void)ConfGetInt("security.lua.max-bytes", &lua_alloc_limit);
+ (void)ConfGetInt("security.lua.max-instructions", &lua_instruction_limit);
+ lua->alloc_limit = lua_alloc_limit;
+ lua->instruction_limit = lua_instruction_limit;
+
if (DetectLuaSetupPrime(de_ctx, lua, s) == -1) {
goto error;
}
return NULL;
}
void *nptr = SCRealloc(ptr, nsize);
-
- ctx->alloc_bytes += nsize;
+ if (nptr != NULL) {
+ ctx->alloc_bytes += nsize;
+ }
return nptr;
}
}
// {LUA_LOADLIBNAME, luaopen_package},
// {LUA_COLIBNAME, luaopen_coroutine},
{ LUA_TABLIBNAME, luaopen_table },
- //{LUA_IOLIBNAME, luaopen_io},
+ // {LUA_IOLIBNAME, luaopen_io},
// {LUA_OSLIBNAME, luaopen_os},
{ LUA_STRLIBNAME, luaopen_string }, { LUA_MATHLIBNAME, luaopen_math },
{ LUA_UTF8LIBNAME, luaopen_utf8 },
sb->L = lua_newstate(sb_alloc, sb); /* create state */
if (sb->L == NULL) {
// TODO: log or error code?
- free(sb);
+ SCFree(sb);
return NULL;
}