]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Mx_check: Fix issue with multiple IPs per MX name
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Aug 2021 15:37:30 +0000 (16:37 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Aug 2021 15:37:30 +0000 (16:37 +0100)
Issue: #3839

src/plugins/lua/mx_check.lua

index e131d16d41803fa1b1d9231147dc09c040a37fea..c88aa56015fd220cc95dd1dd5d792af5aefdc151 100644 (file)
@@ -152,24 +152,23 @@ local function mx_check(task)
         check_results(mxes)
       end
 
-      if err or not results then
+      if err or not results or #results == 0 then
         mxes[name].checked = true
       else
-        -- Try to open TCP connection to port 25
-
-        for _,res in ipairs(results) do
-          local t_ret = rspamd_tcp.new({
-            task = task,
-            host = res:to_string(),
-            callback = io_cb,
-            on_connect = on_connect_cb,
-            timeout = settings.timeout,
-            port = 25
-          })
+        -- Try to open TCP connection to port 25 for a random IP address
+        -- see #3839 on GitHub
+        lua_util.shuffle(results)
+        local t_ret = rspamd_tcp.new({
+          task = task,
+          host = results[1]:to_string(),
+          callback = io_cb,
+          on_connect = on_connect_cb,
+          timeout = settings.timeout,
+          port = 25
+        })
 
-          if not t_ret then
-            mxes[name].checked = true
-          end
+        if not t_ret then
+          mxes[name].checked = true
         end
       end
       check_results(mxes)