7 Commits
Author SHA1 Message Date
Victor Julien e281de36c0 lua/flowvarlib: sanitize length in LuaFlowvarSet()
LuaFlowvarSet() accepted a script-supplied integer for the copy length
without validating it against the actual Lua string length returned by
luaL_checkstring. This could lead to OOB memory access.

This patch checks the length of the string before using it.

Ticket: #8858.
2026-09-11 17:56:55 +02:00
Philippe Antoine 0b239c4848 lua: add bounds checks for flowints and flowvars
Ticket: 8556
2026-05-16 20:42:15 +02:00
Philippe Antoine d1bca4a9b9 util/lua: fix new -Wshorten-64-to-32 warning
Ticket: 6186
2025-05-07 13:59:55 +02:00
Victor Julien 223c568701 lua/flowvarlib: check malloc result
src/util-lua-flowvarlib.c:110:12: warning: If memory allocation fails, then there is a possible null pointer dereference: buf [nullPointerOutOfMemory]
    memcpy(buf, value, len);
           ^
src/util-lua-flowvarlib.c:109:28: note: Assuming allocation function fails
    uint8_t *buf = SCMalloc(len + 1);
                           ^
src/util-lua-flowvarlib.c:109:28: note: Assignment 'buf=malloc(len+1)', assigned value is 0
    uint8_t *buf = SCMalloc(len + 1);
                           ^
src/util-lua-flowvarlib.c:110:12: note: Null pointer dereference
    memcpy(buf, value, len);
           ^
src/util-lua-flowvarlib.c:111:5: warning: If memory allocation fails, then there is a possible null pointer dereference: buf [nullPointerOutOfMemory]
    buf[len] = '\0';
    ^
src/util-lua-flowvarlib.c:109:28: note: Assuming allocation function fails
    uint8_t *buf = SCMalloc(len + 1);
                           ^
src/util-lua-flowvarlib.c:109:28: note: Assignment 'buf=malloc(len+1)', assigned value is 0
    uint8_t *buf = SCMalloc(len + 1);
                           ^
src/util-lua-flowvarlib.c:111:5: note: Null pointer dereference
    buf[len] = '\0';
2025-05-05 21:41:02 +02:00
Jason Ish 096aa9250e lua/flowvarlib: fix unchecked null
Use checkudata, instead of testudata which won't return in case of
NULL, but raise an error in the Lua script.

Fixes:

** CID 1646748:  Null pointer dereferences  (NULL_RETURNS)
/src/util-lua-flowvarlib.c: 89 in LuaFlowvarValue()
2025-04-30 01:25:57 +02:00
Jason Ish 35cf378233 lua/flowvarlib: fix formatting inside clang-format off 2025-04-30 01:25:57 +02:00
Jason Ish 35b03b4077 lua: convert flowvar functions to lib
New Lua lib, "suricata.flowvar" for working with flowvars from Lua.

Replaces functions:
- SCFlowvarGet (and ScFlowvarGet)
- SCFlowvarSet (and SCFlowvarSet)

Of note, the DetectLuaData has been made available to the init and
thread_init methods, instead of just the match. This is due to an
issue that if a flow variable is not registered in init, it will not
be logged, registering in thread_init is too late.

Ticket: #7486
2025-04-27 18:58:47 -06:00