From: Vsevolod Stakhov Date: Thu, 20 Feb 2020 15:56:54 +0000 (+0000) Subject: [Minor] Protect lpeg code against empty texts X-Git-Tag: 2.4~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9bdb819160c5e4f1626b3ddbc76391d8c29995fd;p=thirdparty%2Frspamd.git [Minor] Protect lpeg code against empty texts --- diff --git a/contrib/lua-lpeg/lptree.c b/contrib/lua-lpeg/lptree.c index ffc03f7700..f4a58dbf04 100644 --- a/contrib/lua-lpeg/lptree.c +++ b/contrib/lua-lpeg/lptree.c @@ -1167,12 +1167,26 @@ static int lp_match (lua_State *L) { else if (lua_type (L, SUBJIDX) == LUA_TUSERDATA) { struct rspamd_lua_text *t = lua_check_text (L, SUBJIDX); if (!t) { +#ifdef LPEG_LUD_WORKAROUND + lpeg_free_mem_low (capture); +#endif return luaL_error (L, "invalid argument (not a text)"); } s = t->start; l = t->len; + + if (s == NULL) { + lua_pushnil(L); +#ifdef LPEG_LUD_WORKAROUND + lpeg_free_mem_low (capture); +#endif + return 1; + } } else { +#ifdef LPEG_LUD_WORKAROUND + lpeg_free_mem_low (capture); +#endif return luaL_error (L, "invalid argument"); } size_t i = initposition(L, l);