From 223c5687017bf7d794e23d7619f44099da64c38f Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 3 May 2025 10:20:54 +0200 Subject: [PATCH] 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'; --- src/util-lua-flowvarlib.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util-lua-flowvarlib.c b/src/util-lua-flowvarlib.c index 9d80d349bb..d81f18f95f 100644 --- a/src/util-lua-flowvarlib.c +++ b/src/util-lua-flowvarlib.c @@ -107,6 +107,9 @@ static int LuaFlowvarSet(lua_State *L) } uint8_t *buf = SCMalloc(len + 1); + if (buf == NULL) { + return luaL_error(L, "alloc failure"); + } memcpy(buf, value, len); buf[len] = '\0'; FlowVarAddIdValue(f, *flowvar_id, buf, (uint16_t)len); -- 2.47.3