Subject: | Use of empty (root) FQDNs in Net::DNS::RR->new() broken since 0.64 |
0.64 introduces a change described in the changelog as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Feature/Bug rt.cpan.org #22019
The initial fix for rt 22019 was to strip a trailing dot from all
attributes that where povided as argument for the
Net::DNS::RR::new_from_hash function. We have introduced
Net::DNS::stripdot, a function that will strip the dots of domain
names, taking into account possible escapes (e.g. labels like
foo\\\..). As a side effect the new_from_string method will now
convert possible spaces that are not trapped by some of the
new_from_string functions and convert them to \032 escapes.
For information: The internal storage of domain names is using
presentation format without trailing dots.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unfortunately this change breaks the use of the '' (AKA '.' AKA root)
FQDN in several places, among them Net::DNS::RR::MX->new(..., exchange
=> ''). This has been working correctly since the dawn of time but
broke with 0.64 with the following warning:
Use of uninitialized value $name in scalar chop at
/usr/lib/perl5/Net/DNS.pm line 473
Looking at the implementation of Net::DNS::stripdot, the cause becomes
apparent: $name doesn't get initialized and, if name2labels() returned
an empty list, chop($name) croaks.
The entire implementation of Net::DNS::stripdot doesn't strike me as
particularly good. There's a shorter way to achieve the same thing,
minus the bug; check out my patch.
Subject: | Net-DNS-stripdot-elegance-plus-proper-handling-of-empty-fqdn.diff |
diff -ruN Net-DNS-0.65.org/lib/Net/DNS.pm Net-DNS-0.65/lib/Net/DNS.pm
--- Net-DNS-0.65.org/lib/Net/DNS.pm 2009-10-31 18:37:08.711362341 +0000
+++ Net-DNS-0.65/lib/Net/DNS.pm 2009-10-31 18:42:11.872362054 +0000
@@ -465,13 +465,7 @@
# This utilizes 2 functions in the DNS module to deal with
# thing cracefully.
- my @labels=name2labels(shift);
- my $name;
- foreach my $label (@labels){
- $name .= wire2presentation($label) . ".";
- }
- chop($name);
- return $name;
+ return join('.', map(wire2presentation($_), name2labels(shift)));
}