diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-24 09:06:12 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-24 09:06:12 +0100 |
commit | 231ab5e95dbe16bfcc9696b22536ab70d995c418 (patch) | |
tree | 0cb49083fcabb51804013df2d741eaabf7a3aa56 /lualib/lua_magic/init.lua | |
parent | 9d178a5c16b4db95e83cfe01510664ca59cbe720 (diff) | |
download | rspamd-231ab5e95dbe16bfcc9696b22536ab70d995c418.tar.gz rspamd-231ab5e95dbe16bfcc9696b22536ab70d995c418.zip |
[Minor] Add starting mark to patterns with offset 0
Diffstat (limited to 'lualib/lua_magic/init.lua')
-rw-r--r-- | lualib/lua_magic/init.lua | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lualib/lua_magic/init.lua b/lualib/lua_magic/init.lua index 0784b4a77..2fb848707 100644 --- a/lualib/lua_magic/init.lua +++ b/lualib/lua_magic/init.lua @@ -62,8 +62,14 @@ local function process_patterns(log_obj) short_patterns[#short_patterns + 1] = { str, match, pattern } - lua_util.debugm(N, log_obj, 'add short pattern %s for ext %s', - str, pattern.ext) + if str:sub(1, 1) == '^' then + lua_util.debugm(N, log_obj, 'add head pattern %s for ext %s', + str, pattern.ext) + else + lua_util.debugm(N, log_obj, 'add short pattern %s for ext %s', + str, pattern.ext) + end + if max_short_offset < match.position then max_short_offset = match.position @@ -94,6 +100,12 @@ local function process_patterns(log_obj) if match.string then if match.relative_position and not match.position then match.position = match.relative_position + #match.string + + if match.relative_position == 0 then + if match.string:sub(1, 1) ~= '^' then + match.string = '^' .. match.string + end + end end add_processed(match.string, match, pattern) elseif match.hex then @@ -107,6 +119,9 @@ local function process_patterns(log_obj) if match.relative_position and not match.position then match.position = match.relative_position + #match.hex / 2 end + if match.relative_position == 0 then + table.insert(hex_table, 1, '^') + end add_processed(table.concat(hex_table), match, pattern) end end |