]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix some more lua compat issues with text:find
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Nov 2020 11:34:03 +0000 (11:34 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Nov 2020 11:34:03 +0000 (11:34 +0000)
src/libutil/str_util.c
src/lua/lua_text.c
test/lua/unit/rspamd_text.lua

index 80f94707a3858a7dfed4df9830585ed74f21fb35..1e7d0b06b6cefe9f47bac0bc7e5e865f1d043558 100644 (file)
@@ -1891,6 +1891,9 @@ rspamd_substring_search (const gchar *in, gsize inlen,
 
                        return (-1);
                }
+               else if (G_UNLIKELY (srchlen == 0)) {
+                       return 0;
+               }
 
                return rspamd_substring_search_common (in, inlen, srch, srchlen,
                                rspamd_substring_cmp_func);
index dbbba98382b31babd37e2b85275c2894a49bdcac..23e908c670c0864798ce1efc0e609fed35b90a90 100644 (file)
@@ -1358,12 +1358,14 @@ lua_text_find (lua_State *L)
                        init = relative_pos_start (lua_tointeger (L, 3), t->len);
                }
 
+               init --;
+
                if (init > t->len) {
                        return luaL_error (L, "invalid arguments to find: init too large");
                }
 
-               goffset pos = rspamd_substring_search (t->start + init - 1,
-                               t->len - (init - 1),
+               goffset pos = rspamd_substring_search (t->start + init,
+                               t->len - init,
                                pat, patlen);
 
                if (pos == -1) {
index 3e6d0fff7c4f359fb078ef98cf486f15e399b346..d643d9e63411c0d4274cb3fc376361f915cd4b32 100644 (file)
@@ -39,6 +39,9 @@ context("Rspamd_text:find() test", function()
     {{'foobarfoo', 'rfoo'}, {6, 9}},
     {{'foo', 'bar'}, nil},
     {{'x', 'xxxx'}, nil},
+    {{'', ''}, {1, 0}},
+    {{'', '_'}, nil},
+    {{'x', ''}, {1, 0}},
   }
 
   for _, case in ipairs(cases) do