]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Remove fann with incorrect layers count
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 15 Oct 2016 13:44:20 +0000 (14:44 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 15 Oct 2016 13:44:20 +0000 (14:44 +0100)
src/plugins/lua/fann_scores.lua

index 9647fd3d320213e14078e9f51221ef39fb541bdc..d1564cd2e5cc75f1d89e109d7024e6c29b865e8b 100644 (file)
@@ -311,8 +311,21 @@ local function load_fann(id)
           fname, err)
       end
     else
-      rspamd_logger.infox(rspamd_config, 'loaded fann from %s', fname)
-      return true
+      local layers = data[id].fann:get_layers()
+
+      if not layers or #layers ~= 5 then
+        rspamd_logger.infox(rspamd_config, 'fann has incorrect number of layers: %s, removing',
+          #layers)
+        data[id].fann = nil
+        local ret,err = rspamd_util.unlink(fname)
+        if not ret then
+          rspamd_logger.errx(rspamd_config, 'cannot remove invalid fann from %s: %s',
+            fname, err)
+        end
+      else
+        rspamd_logger.infox(rspamd_config, 'loaded fann from %s', fname)
+        return true
+      end
     end
   else
     rspamd_logger.infox(rspamd_config, 'fann is invalid: "%s"; removing', fname)