From 0461b74b2286f77b5ebcd48d8cccb7ddcf2a3395 Mon Sep 17 00:00:00 2001 From: Laurence Jones Date: Tue, 7 Nov 2023 08:39:25 +0000 Subject: [PATCH] Add a nil check to the parse ip function (#50) --- lib/crowdsec.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/crowdsec.lua b/lib/crowdsec.lua index 644f8ca..4d37c42 100644 --- a/lib/crowdsec.lua +++ b/lib/crowdsec.lua @@ -151,6 +151,9 @@ local function item_to_string(item, scope) end local ip_network_address, is_ipv4 = iputils.parseIPAddress(ip) + if ip_network_address == nil then + return nil + end if is_ipv4 then ip_version = "ipv4" if cidr == nil then @@ -393,6 +396,9 @@ function csmod.allowIp(ip) csmod.SetupStream() local key = item_to_string(ip, "ip") + if key == nil then + return true, nil, "Check failed '" .. ip .. "' has no valid IP address" + end local key_parts = {} for i in key.gmatch(key, "([^_]+)") do table.insert(key_parts, i)