From 23fb83c41635c3d89fad17d2e74dbcada86fe0e2 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 19 Feb 2020 02:07:30 +0000 Subject: [PATCH] Bug 24538: Handle Net::Netmask parser errors This patch switches from the new() to new2() constructor, which will return an undef value when it fails to parse a value. This patch warns on parser failures, but otherwise silently drops the invalid value, and returns objects for any valid input it can parse. This way one mistake won't disable the whole feature. To test: 1. Run the unit test t/Koha/Middlware/RealIP.t Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/Middleware/RealIP.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Koha/Middleware/RealIP.pm b/Koha/Middleware/RealIP.pm index 22f40dbff4..88a843dbcf 100644 --- a/Koha/Middleware/RealIP.pm +++ b/Koha/Middleware/RealIP.pm @@ -106,7 +106,16 @@ sub get_trusted_proxies { my $proxies_conf = C4::Context->config('koha_trusted_proxies'); return unless $proxies_conf; my @trusted_proxies_ip = split( / /, $proxies_conf ); - my @trusted_proxies = map { Net::Netmask->new($_) } @trusted_proxies_ip; + my @trusted_proxies = (); + foreach my $ip (@trusted_proxies_ip){ + my $mask = Net::Netmask->new2($ip); + if ($mask){ + push(@trusted_proxies,$mask); + } + else { + warn "$Net::Netmask::error"; + } + } return \@trusted_proxies; } -- 2.20.1