From: Vsevolod Stakhov Date: Fri, 11 Oct 2019 08:57:20 +0000 (+0100) Subject: [Minor] Distinguish absent IP address in a more sane way X-Git-Tag: 2.0~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9f755c976a708b8a9836ed83f05bdd290b55d54;p=thirdparty%2Frspamd.git [Minor] Distinguish absent IP address in a more sane way --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index b04596ed35..97523a1fac 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -3843,7 +3843,12 @@ lua_task_get_from_ip (lua_State *L) struct rspamd_task *task = lua_check_task (L, 1); if (task) { - rspamd_lua_ip_push (L, task->from_addr); + if (task->from_addr) { + rspamd_lua_ip_push (L, task->from_addr); + } + else { + lua_pushnil (L); + } } else { return luaL_error (L, "invalid arguments"); @@ -3901,7 +3906,12 @@ lua_task_get_client_ip (lua_State *L) struct rspamd_task *task = lua_check_task (L, 1); if (task) { - rspamd_lua_ip_push (L, task->client_addr); + if (task->client_addr) { + rspamd_lua_ip_push (L, task->client_addr); + } + else { + lua_pushnil (L); + } } else { return luaL_error (L, "invalid arguments"); diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua index f922f63d29..ab8a3bf537 100644 --- a/src/plugins/lua/dmarc.lua +++ b/src/plugins/lua/dmarc.lua @@ -181,7 +181,7 @@ local dmarc_grammar = gen_dmarc_grammar() local function dmarc_report(task, spf_ok, dkim_ok, disposition, sampled_out, hfromdom, spfdom, dres, spf_result) local ip = task:get_from_ip() - if not ip:is_valid() then + if ip and not ip:is_valid() then return nil end local rspamd_lua_utils = require "lua_util" diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index 7016d9c5ea..f66186fa6f 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -391,7 +391,7 @@ local function gen_rbl_callback(rule) local function check_local(task, _) local ip = task:get_from_ip() - if not ip:is_valid() then + if ip and not ip:is_valid() then ip = nil end diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index 5fe2353d48..0f895dc0b5 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -552,7 +552,7 @@ local function process_settings_table(tbl, allow_ids, mempool) check = gen_check_closure(convert_to_table(elt.ip, ips_table), check_ip_setting), extract = function(task) local ip = task:get_from_ip() - if ip:is_valid() then return ip end + if ip and ip:is_valid() then return ip end return nil end, }