diff --git a/src/output-lua-common.c b/src/output-lua-common.c index 4760a95e19..aec17e0002 100644 --- a/src/output-lua-common.c +++ b/src/output-lua-common.c @@ -63,23 +63,6 @@ int LuaCallbackError(lua_State *luastate, const char *msg) return 2; } -int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len) -{ - /* we're using a buffer sized at a multiple of 4 as lua_pushlstring generates - * invalid read errors in valgrind otherwise. Adding in a nul to be sure. - * - * Buffer size = len + 1 (for nul) + whatever makes it a multiple of 4 */ - size_t buflen = input_len + 1 + ((input_len + 1) % 4); - uint8_t buf[buflen]; - memset(buf, 0x00, buflen); - memcpy(buf, input, input_len); - buf[input_len] = '\0'; - - /* return value through luastate, as a luastring */ - lua_pushlstring(luastate, (char *)buf, input_len); - return 1; -} - const char *LuaGetStringArgument(lua_State *luastate, int argc) { /* get argument */ diff --git a/src/output-lua-common.h b/src/output-lua-common.h index 2e68634821..c19045c93d 100644 --- a/src/output-lua-common.h +++ b/src/output-lua-common.h @@ -27,7 +27,6 @@ #ifdef HAVE_LUA int LuaCallbackError(lua_State *luastate, const char *msg); -int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len); const char *LuaGetStringArgument(lua_State *luastate, int argc); void LogLuaPushTableKeyValueInt(lua_State *luastate, const char *key, int value); diff --git a/src/util-lua.c b/src/util-lua.c index 446598a570..b091445ab4 100644 --- a/src/util-lua.c +++ b/src/util-lua.c @@ -234,7 +234,21 @@ void LuaPrintStack(lua_State *state) { } } - - +int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len) +{ + /* we're using a buffer sized at a multiple of 4 as lua_pushlstring generates + * invalid read errors in valgrind otherwise. Adding in a nul to be sure. + * + * Buffer size = len + 1 (for nul) + whatever makes it a multiple of 4 */ + size_t buflen = input_len + 1 + ((input_len + 1) % 4); + uint8_t buf[buflen]; + memset(buf, 0x00, buflen); + memcpy(buf, input, input_len); + buf[input_len] = '\0'; + + /* return value through luastate, as a luastring */ + lua_pushlstring(luastate, (char *)buf, input_len); + return 1; +} #endif /* HAVE_LUA */ diff --git a/src/util-lua.h b/src/util-lua.h index eb7a637e35..7ea69915b9 100644 --- a/src/util-lua.h +++ b/src/util-lua.h @@ -84,6 +84,8 @@ void LuaStateSetStreamingBuffer(lua_State *luastate, LuaStreamingBuffer *b); void LuaPrintStack(lua_State *state); +int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len); + #endif /* HAVE_LUA */ #endif /* __UTIL_LUA_H__ */