Skip to content

Commit 71689a6

Browse files
committed
lua: don't accept a table as a return value from match
Remove the half finished support for accepting a table returned from a Lua rule's match function. This is not documented, not tested, and not really implemented. Also, use lua_tointeger to get the return value from the match function as an integer instead of a float. Ticket: OISF#6941
1 parent 495a12f commit 71689a6

1 file changed

Lines changed: 5 additions & 37 deletions

File tree

src/detect-lua.c

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -213,45 +213,13 @@ static int DetectLuaRunMatch(
213213
if (lua_gettop(tlua->luastate) > 0) {
214214
/* script returns a number (return 1 or return 0) */
215215
if (lua_type(tlua->luastate, 1) == LUA_TNUMBER) {
216-
double script_ret = lua_tonumber(tlua->luastate, 1);
217-
SCLogDebug("script_ret %f", script_ret);
216+
lua_Integer script_ret = lua_tointeger(tlua->luastate, 1);
217+
SCLogDebug("script_ret %lld", script_ret);
218218
lua_pop(tlua->luastate, 1);
219-
220-
if (script_ret == 1.0)
219+
if (script_ret == 1)
221220
match = 1;
222-
223-
/* script returns a table */
224-
} else if (lua_type(tlua->luastate, 1) == LUA_TTABLE) {
225-
lua_pushnil(tlua->luastate);
226-
const char *k, *v;
227-
while (lua_next(tlua->luastate, -2)) {
228-
v = lua_tostring(tlua->luastate, -1);
229-
lua_pop(tlua->luastate, 1);
230-
k = lua_tostring(tlua->luastate, -1);
231-
232-
if (!k || !v)
233-
continue;
234-
235-
SCLogDebug("k='%s', v='%s'", k, v);
236-
237-
if (strcmp(k, "retval") == 0) {
238-
int val;
239-
if (StringParseInt32(&val, 10, 0, (const char *)v) < 0) {
240-
SCLogError("Invalid value "
241-
"for \"retval\" from LUA return table: '%s'",
242-
v);
243-
match = 0;
244-
}
245-
else if (val == 1) {
246-
match = 1;
247-
}
248-
} else {
249-
/* set flow var? */
250-
}
251-
}
252-
253-
/* pop the table */
254-
lua_pop(tlua->luastate, 1);
221+
} else {
222+
SCLogDebug("Unsupported datatype returned from Lua script");
255223
}
256224
}
257225

0 commit comments

Comments
 (0)