[PATCH 1/1] lua: avoid stack allocation of potentially large input string

4 views
Skip to first unread message

Storm, Christian

unread,
Apr 21, 2026, 10:25:33 AM (23 hours ago) Apr 21
to swupdate, MOESSBAUER, Felix
From: Felix Moessbauer <felix.mo...@siemens.com>

Previously the json string types where copied to a stack-allocated
buffer, which is problematic if the stack sizes are small.

We replace this by the corresponding json-c function, which further
avoids custom logic to de-quote the string.

Fixes: 4c84360b ("suricatta/lua: Add suricatta Lua module ...")
Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
suricatta/server_lua.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/suricatta/server_lua.c b/suricatta/server_lua.c
index b1e559c9..558b3dc1 100644
--- a/suricatta/server_lua.c
+++ b/suricatta/server_lua.c
@@ -279,12 +279,7 @@ static int json_push_to_table(lua_State *L, json_object *jsobj)
{
switch (json_object_get_type(jsobj)) {
case json_type_string: {
- /* Unquote JSON string to push it unquoted to Lua. */
- char *trimmed = strdupa(json_object_to_json_string(jsobj));
- trimmed = trimmed[0] == '"' ? trimmed + 1 : trimmed;
- size_t len = strlen(trimmed);
- trimmed[len - 1] = trimmed[len - 1] == '"' ? '\0' : trimmed[len - 1];
- lua_pushstring(L, trimmed);
+ lua_pushstring(L, json_object_get_string(jsobj));
break;
}
case json_type_boolean:
--
2.53.0
Reply all
Reply to author
Forward
0 new messages