lua: don't attempt to garbage collect a null value

When not sandboxed, a script can get access to the metatable and call
`.__gc` with an invalid value like nil, causing a NULL pointer dereference
in Suricata.

Ticket: #8248
pull/14697/head
Jason Ish 7 months ago
parent b944e3b1ed
commit 5d61f5253d

@ -42,8 +42,10 @@ static int LuaDatasetGC(lua_State *luastate)
{
SCLogDebug("gc:start");
struct LuaDataset *s = (struct LuaDataset *)lua_touserdata(luastate, 1);
SCLogDebug("deref %s", s->set->name);
s->set = NULL;
if (s != NULL && s->set != NULL) {
SCLogDebug("deref %s", s->set->name);
s->set = NULL;
}
SCLogDebug("gc:done");
return 0;
}

@ -45,8 +45,10 @@ static int LuaFlowGC(lua_State *luastate)
{
SCLogDebug("gc:start");
struct LuaFlow *s = (struct LuaFlow *)lua_touserdata(luastate, 1);
SCLogDebug("flow %p", s->f);
s->f = NULL;
if (s != NULL) {
SCLogDebug("flow %p", s->f);
s->f = NULL;
}
SCLogDebug("gc:done");
return 0;
}

@ -45,8 +45,10 @@ static int LuaPacketGC(lua_State *luastate)
{
SCLogDebug("gc:start");
struct LuaPacket *s = (struct LuaPacket *)lua_touserdata(luastate, 1);
SCLogDebug("packet %p", s->p);
s->p = NULL;
if (s != NULL) {
SCLogDebug("packet %p", s->p);
s->p = NULL;
}
SCLogDebug("gc:done");
return 0;
}

Loading…
Cancel
Save