From 4f647f2fd0246ff9d97c160fdc0f59bee50acefb Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 22 May 2024 08:22:27 +0200 Subject: [PATCH 1/2] error out if the lookup fails --- lib/Mail/SPF/Server.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Mail/SPF/Server.pm b/lib/Mail/SPF/Server.pm index e1a6b03..5a8a279 100644 --- a/lib/Mail/SPF/Server.pm +++ b/lib/Mail/SPF/Server.pm @@ -570,7 +570,10 @@ sub dns_lookup { $domain =~ s/^(.*?)\.?$/\L$1/; # Normalize domain. - my $packet = $self->dns_resolver->send($domain, $rr_type); + my $packet = eval { $self->dns_resolver->send($domain, $rr_type); }; + if($@) { + throw Mail::SPF::ENoAcceptableRecord($@); + } # Throw DNS exception unless an answer packet with RCODE 0 or 3 (NXDOMAIN) # was received (thereby treating NXDOMAIN as an acceptable but empty answer packet): From a7be3509ef1e8fa15993395dba78800502ff5d91 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 22 May 2024 08:26:54 +0200 Subject: [PATCH 2/2] use "try" instead of "eval" --- lib/Mail/SPF/Server.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Mail/SPF/Server.pm b/lib/Mail/SPF/Server.pm index 5a8a279..08d4dce 100644 --- a/lib/Mail/SPF/Server.pm +++ b/lib/Mail/SPF/Server.pm @@ -570,14 +570,16 @@ sub dns_lookup { $domain =~ s/^(.*?)\.?$/\L$1/; # Normalize domain. - my $packet = eval { $self->dns_resolver->send($domain, $rr_type); }; - if($@) { - throw Mail::SPF::ENoAcceptableRecord($@); + try { + $packet = $self->dns_resolver->send($domain, $rr_type); } + otherwise { + throw Mail::SPF::ENoAcceptableRecord($self->dns_resolver->errorstring); + }; # Throw DNS exception unless an answer packet with RCODE 0 or 3 (NXDOMAIN) # was received (thereby treating NXDOMAIN as an acceptable but empty answer packet): - $self->dns_resolver->errorstring !~ /^(timeout|query timed out)$/ + defined $self->dns_resolver->errorstring and $self->dns_resolver->errorstring !~ /^(timeout|query timed out)$/ or throw Mail::SPF::EDNSTimeout( "Time-out on DNS '$rr_type' lookup of '$domain'"); defined($packet)