Skip to content

Commit

Permalink
Merge pull request #26 from fastmail/net-dns-error-fix
Browse files Browse the repository at this point in the history
Fix issue where certain DNS results would cause an exception to be thrown
  • Loading branch information
marcbradshaw authored Sep 23, 2024
2 parents c50b99c + c46807e commit b79efc1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/Mail/SPF/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,12 @@ sub dns_lookup {

# 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):
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)
or throw Mail::SPF::EDNSError(
"Unknown error on DNS '$rr_type' lookup of '$domain'");
$packet->header->rcode =~ /^(NOERROR|NXDOMAIN)$/
or throw Mail::SPF::EDNSError(
"'" . $packet->header->rcode . "' error on DNS '$rr_type' lookup of '$domain'");
throw Mail::SPF::EDNSTimeout("Time-out on DNS '$rr_type' lookup of '$domain'")
if defined $self->dns_resolver->errorstring && $self->dns_resolver->errorstring =~ /^(timeout|query timed out)$/;
throw Mail::SPF::EDNSError("Unknown error on DNS '$rr_type' lookup of '$domain'")
unless defined $packet;
throw Mail::SPF::EDNSError("'" . $packet->header->rcode . "' error on DNS '$rr_type' lookup of '$domain'")
unless $packet->header->rcode =~ /^(NOERROR|NXDOMAIN)$/;

return $packet;
}
Expand Down

0 comments on commit b79efc1

Please sign in to comment.