If an IP address being looked up has a CNAME instead of a PTR, for example:
210.7.246.87.in-addr.arpa. 600 IN CNAME 210.0-255.7.246.87.in-addr.arpa.
The block subroutine assumes that the RR type is a PTR record, and triggers an error in the Net::DNS:RR::CNAME class by attempting to access the ptrdname method, which doesn't exist. The error is ugly:
`*** FATAL PROGRAM ERROR!! Unknown instance method "ptrdname"
*** which the program has attempted to call for the object:
210.7.246.87.in-addr.arpa. 600 IN CNAME 210.0-255.7.246.87.in-addr.arpa.
*** THIS IS A BUG IN THE CALLING SOFTWARE, which incorrectly assumes
*** that the object would be of a particular type. The type of an
*** object should be checked before calling any of its methods.
Net::DNS::RR::CNAME 1597 at /usr/local/sbin/bruteforceblocker line 129, line 1.
main::block("87.246.7.210") called at /usr/local/sbin/bruteforceblocker line 101
`
A patch that fixes it:
`diff --git a/bruteforceblocker.pl b/bruteforceblocker.pl
index 71c4f23..78354b8 100755
--- a/bruteforceblocker.pl
+++ b/bruteforceblocker.pl
@@ -127,6 +127,11 @@ sub block {
my ($IP) = shift or die "Need IP!\n";
my $query = $res->search($IP, "PTR");
-
while ($query && ($query->answer)[0]->type eq "CNAME") {
-
$query = $res->search(($query->answer)[0]->cname, "PTR");
-
}
-
my $RDNS = $query ? ($query->answer)[0]->ptrdname : "not resolved";
if ($timea{$IP} && ($timea{$IP} < time - $cfg->{timeout})) {
`