From 87ef9084fbc26218762f7b9a90522507543d142a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 18 Nov 2020 17:50:19 +0000 Subject: [Fix] Fix off-by-one with init check --- src/lua/lua_text.c | 2 +- test/lua/unit/rspamd_text.lua | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c index 99b8b8151..dbbba9838 100644 --- a/src/lua/lua_text.c +++ b/src/lua/lua_text.c @@ -1358,7 +1358,7 @@ lua_text_find (lua_State *L) init = relative_pos_start (lua_tointeger (L, 3), t->len); } - if (init >= t->len) { + if (init > t->len) { return luaL_error (L, "invalid arguments to find: init too large"); } diff --git a/test/lua/unit/rspamd_text.lua b/test/lua/unit/rspamd_text.lua index 4e3a5e8e7..3e6d0fff7 100644 --- a/test/lua/unit/rspamd_text.lua +++ b/test/lua/unit/rspamd_text.lua @@ -37,6 +37,8 @@ context("Rspamd_text:find() test", function() {{'foobarfoo', 'bar'}, {4, 6}}, {{'foobarfoo', 'baz'}, nil}, {{'foobarfoo', 'rfoo'}, {6, 9}}, + {{'foo', 'bar'}, nil}, + {{'x', 'xxxx'}, nil}, } for _, case in ipairs(cases) do -- cgit v1.2.3