lua/datasets: error on :add before :get

LuaDatasetAdd() dereferenced s->set without ensuring :get had been
called first. The userdata metatable validation it was originally
part of is already in place (Ticket: #8882); what remained is the
missing init check.

Reject :add on an uninitialized dataset. The pointer itself is
zeroed in a follow-up commit.

Ticket: #8882.
pull/16213/head
Victor Julien 2 months ago committed by Victor Julien
parent e281de36c0
commit f5ea9e8480

@ -71,12 +71,9 @@ static int LuaDatasetGetRef(lua_State *luastate)
static int LuaDatasetAdd(lua_State *luastate)
{
SCLogDebug("add:start");
struct LuaDataset *s = (struct LuaDataset *)luaL_checkudata(luastate, 1, "dataset::metatable");
if (!lua_isstring(luastate, 2)) {
LUA_ERROR("1st arg is not a string");
}
if (!lua_isnumber(luastate, 3)) {
LUA_ERROR("2nd arg is not a number");
struct LuaDataset *s = luaL_checkudata(luastate, 1, "dataset::metatable");
if (s->set == NULL) {
LUA_ERROR("dataset is not initialized (call :get first)");
}
const uint8_t *str = (const uint8_t *)lua_tostring(luastate, 2);

Loading…
Cancel
Save