From 2e766a7e1674855fb23de00f617717ebf4e96ddf Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Sep 2025 13:40:25 +0200 Subject: [PATCH] fix potential NULL deref of string in lua chatprint lib functions --- src/lua_baselib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index fb2b7a36f..5af1a79b0 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -99,11 +99,12 @@ static int lib_chatprint(lua_State *L) { const char *str = luaL_checkstring(L, 1); // retrieve string boolean sound = lua_optboolean(L, 2); // retrieve sound boolean - int len = strlen(str); if (str == NULL) // error if we don't have a string! return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprint")); + int len = strlen(str); + if (len > 255) // string is too long!!! return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer."); @@ -117,7 +118,6 @@ static int lib_chatprintf(lua_State *L) int n = lua_gettop(L); /* number of arguments */ const char *str = luaL_checkstring(L, 2); // retrieve string boolean sound = lua_optboolean(L, 3); // sound? - int len = strlen(str); player_t *plr; if (n < 2) @@ -133,6 +133,8 @@ static int lib_chatprintf(lua_State *L) if (str == NULL) // error if we don't have a string! return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprintf")); + int len = strlen(str); + if (len > 255) // string is too long!!! return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer.");