diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2016-07-07 10:20:39 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2016-07-07 10:20:39 +0300 |
commit | e93c1c0c513c1f33a68371a22564a919853d3cef (patch) | |
tree | dedd763d4439abccab64c16e29a1e3938c4a18ca /src | |
parent | 4556f6818f9a6626a35319cc6a6a7207dba1f093 (diff) | |
download | rspamd-e93c1c0c513c1f33a68371a22564a919853d3cef.tar.gz rspamd-e93c1c0c513c1f33a68371a22564a919853d3cef.zip |
[Fix] Fix next-to-last extension length check
- Insert `symbol_bad_extension` even if length check fails for double extension
- Use extension length check with non-archive bad extensions as well
- Optimize check_mime_type funtion code
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/mime_types.lua | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index f6ae28282..50f99e045 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -79,15 +79,16 @@ local function check_mime_type(task) ext = parts[#parts] end - if ext then - local badness_mult = settings['bad_extensions'][ext] + local function check_extension(badness_mult) if badness_mult then - -- Check if next-to-last extension is not a number - if #parts > 2 and not string.match(parts[#parts - 1], '^%d+$') then + if #parts > 2 + -- We need to ensure that it is an extension, so we check for its length + and #parts[#parts - 1] <= 4 + -- Check if next-to-last extension is not a number + and not string.match(parts[#parts - 1], '^%d+$') then -- Double extension + bad extension == VERY bad task:insert_result(settings['symbol_double_extension'], badness_mult, { - parts[#parts - 1], - parts[#parts] + parts[#parts - 1], parts[#parts] }) else -- Just bad extension @@ -95,22 +96,14 @@ local function check_mime_type(task) end end + end + + if ext then + check_extension(settings['bad_extensions'][ext]) + -- Also check for archive bad extension if is_archive then - badness_mult = settings['bad_archive_extensions'][ext] - if badness_mult then - -- Check if next-to-last extension is not a number - if #parts > 2 and not string.match(parts[#parts - 1], '^%d+$') then - -- We need to ensure that it is an extension, so we check for its length - if #parts[#parts - 1] <= 4 then - -- Double extension + bad extension == VERY bad - task:insert_result(settings['symbol_double_extension'], badness_mult, fname) - end - else - -- Just bad extension - task:insert_result(settings['symbol_bad_extension'], badness_mult, fname) - end - end + check_extension(settings['bad_archive_extensions'][ext]) if settings['archive_extensions'][ext] then -- Archive in archive |