Subject: | DNS resolution broken when options ndots used in /etc/resolv.conf (regression as of 1.11+) |
Hello!
Net::DNS 1.11+ incorrectly handles /etc/resolv.conf's `options ndots:` option.
Net::DNS 1.10 is the last version without a bug.
Net::DNS 1.11+ has the same bug as Ruby used to have but was fixed in Ruby 2.1 and backported to 2.0: https://bugs.ruby-lang.org/issues/10412. If search within domains listed in /etc/resolv.conf fails, the check should fallback to a bare domain. This is how the operating system works (getent hosts / getaddrinfo), how other programming languages work, and a list goes on.
# Reproduction
```
echo "search example.com\noptions ndots:5" >> /etc/hosts
cpanm -n Net::DNS~'== 1.10'
perl -MData::Dumper -MNet::DNS::Resolver -e 'print Dumper(Net::DNS::Resolver->new(nameservers => qw('a.root-servers.net'), recurse => 0, retrans => 2, retry => 1)->send('google.com', 'A'));'
# => ... gets you the records as intended
cpanm -n Net::DNS~'== 1.11'
perl -MData::Dumper -MNet::DNS::Resolver -e 'print Dumper(Net::DNS::Resolver->new(nameservers => qw('a.root-servers.net'), recurse => 0, retrans => 2, retry => 1)->send('google.com', 'A'));'
# => unresolvable name: a.root-servers.net at -e line 1.
```
Passing extra options like `ndots => 1, dnsrch => 0, defnames => 0` to `Net::DNS::Resolver->new` has no effect.
# Analysis
Use this command to see dump the resolver:
```
perl -MData::Dumper -MNet::DNS::Resolver -e 'print Dumper(Net::DNS::Resolver->new(nameservers => qw('a.root-servers.net'), recurse => 0, retrans => 2, retry => 1));'
```
This will show an empty value for nameserver4
# Workarounds
1. Change the nameserver from 'a.root-servers.net' to 'a.root-servers.net.'
2. Use `nameserver4 => ...` instead of `nameservers => ...`.
```
perl -MData::Dumper -MNet::DNS::Resolver -e 'print Dumper(Net::DNS::Resolver->new(nameserver4 => qw('a.root-servers.net'), recurse => 0, retrans => 2, retry => 1)->send('google.com', 'A'));'
```
3. Downgrade to 1.10.