]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Protect lpeg code against empty texts
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 20 Feb 2020 15:56:54 +0000 (15:56 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 20 Feb 2020 15:56:54 +0000 (15:56 +0000)
contrib/lua-lpeg/lptree.c

index ffc03f7700b594c677d3c31719c74c155d33f543..f4a58dbf046ee811b13e6ae8d5a2326c13c2aabe 100644 (file)
@@ -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);