commit ff7c63b: [Minor] Fix some more lua compat issues with text:find
Vsevolod Stakhov
vsevolod at highsecure.ru
Thu Nov 19 11:35:07 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-11-19 11:34:03 +0000
URL: https://github.com/rspamd/rspamd/commit/ff7c63b24d8e20fa4c75e408a5d29c44b154819f (HEAD -> master)
[Minor] Fix some more lua compat issues with text:find
---
src/libutil/str_util.c | 3 +++
src/lua/lua_text.c | 6 ++++--
test/lua/unit/rspamd_text.lua | 3 +++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 80f94707a..1e7d0b06b 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -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);
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index dbbba9838..23e908c67 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -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) {
diff --git a/test/lua/unit/rspamd_text.lua b/test/lua/unit/rspamd_text.lua
index 3e6d0fff7..d643d9e63 100644
--- a/test/lua/unit/rspamd_text.lua
+++ b/test/lua/unit/rspamd_text.lua
@@ -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
More information about the Commits
mailing list