From: Vsevolod Stakhov Date: Wed, 18 Nov 2020 17:50:19 +0000 (+0000) Subject: [Fix] Fix off-by-one with init check X-Git-Tag: 2.7~134 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=87ef9084fbc26218762f7b9a90522507543d142a;p=rspamd.git [Fix] Fix off-by-one with init check --- 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