aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_meta.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualib/lua_meta.lua')
-rw-r--r--lualib/lua_meta.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/lualib/lua_meta.lua b/lualib/lua_meta.lua
index 3ed416158..b7c9286d7 100644
--- a/lualib/lua_meta.lua
+++ b/lualib/lua_meta.lua
@@ -18,6 +18,7 @@ local exports = {}
local N = "metatokens"
local ts = require("tableshape").types
+local logger = require "rspamd_logger"
-- Metafunctions
local function meta_size_function(task)
@@ -454,6 +455,11 @@ local function rspamd_gen_metatokens(task, names)
for i,tok in ipairs(ct) do
lua_util.debugm(N, task, "metatoken: %s = %s",
mt.names[i], tok)
+ if tok ~= tok or tok == math.huge() then
+ logger.errx(task, 'metatoken %s returned %s; replace it with 0 for sanity',
+ mt.names[i], tok)
+ tok = 0.0
+ end
table.insert(metatokens, tok)
end
end
@@ -462,10 +468,15 @@ local function rspamd_gen_metatokens(task, names)
end
else
- local logger = require "rspamd_logger"
for _,n in ipairs(names) do
if metatokens_by_name[n] then
- table.insert(metatokens, metatokens_by_name[n](task))
+ local tok = metatokens_by_name[n](task)
+ if tok ~= tok or tok == math.huge() then
+ logger.errx(task, 'metatoken %s returned %s; replace it with 0 for sanity',
+ n, tok)
+ tok = 0.0
+ end
+ table.insert(metatokens, tok)
else
logger.errx(task, 'unknown metatoken: %s', n)
end
@@ -485,7 +496,6 @@ local function rspamd_gen_metatokens_table(task)
local ct = mt.cb(task)
for i,tok in ipairs(ct) do
if tok ~= tok or tok == math.huge() then
- local logger = require "rspamd_logger"
logger.errx(task, 'metatoken %s returned %s; replace it with 0 for sanity',
mt.names[i], tok)
tok = 0.0
@@ -519,7 +529,6 @@ exports.add_metafunction = function(tbl)
local ret, err = meta_schema(tbl)
if not ret then
- local logger = require "rspamd_logger"
logger.errx('cannot add metafunction: %s', err)
else
table.insert(metafunctions, tbl)