]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix DCC `rep` handling vstakhov-fix-dcc 5161/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 27 Sep 2024 11:51:38 +0000 (12:51 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 27 Sep 2024 11:58:53 +0000 (12:58 +0100)
Issue: #5158

lualib/lua_scanners/dcc.lua

index 8d5e9e10a87cf2032d4e4c5d528d3fa8d3cfbc28..186d1543db973d90868c3f3c857f9626bcb576e8 100644 (file)
@@ -198,13 +198,18 @@ local function dcc_check(task, content, digest, rule)
             local opts = {}
             local score = 0.0
             info = info:lower()
-            local rep = info:match('rep=([^=%s]+)')
+            local rep = info:match('rep=(%d+)')
 
             -- Adjust reputation if available
             if rep then
-              rep = tonumber(rep)
-            end
-            if not rep then
+              rep = (tonumber(rep) or 100.0) / 100.0
+
+              if rep > 1.0 then
+                rep = 1.0
+              elseif rep < 0.0 then
+                rep = 0.0
+              end
+            else
               rep = 1.0
             end
 
@@ -213,12 +218,12 @@ local function dcc_check(task, content, digest, rule)
               if num == 'many' then
                 rnum = lim
               else
-                rnum = tonumber(num)
+                rnum = tonumber(num) or lim
               end
 
               if rnum and rnum >= lim then
                 opts[#opts + 1] = string.format('%s=%s', what, num)
-                score = score + rep / 3.0
+                score = score * rep
               end
             end