Bug #10550
closedResolv::DNS.getaddresses returns no IPs when nameserver returns in differing case than query
Description
Our servers are hosted with Rackspace and following patching of BIND, their DNS servers started returning different casing for the ANSWER. For example, here is me resolving sendgrid.com. You'll see the first command returns "sendgrid.com" in the answer section, while another returns "SENDGRID.COM".
$ dig sendgrid.com
; <<>> DiG 9.8.1-P1 <<>> sendgrid.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7895
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;sendgrid.com. IN A
;; ANSWER SECTION:
sendgrid.com. 5 IN A 104.20.21.26
sendgrid.com. 5 IN A 104.20.20.26
;; Query time: 2 msec
;; SERVER: 69.20.0.164#53(69.20.0.164)
;; WHEN: Wed Nov 26 22:21:04 2014
;; MSG SIZE rcvd: 62
$ dig sendgrid.com
; <<>> DiG 9.8.1-P1 <<>> sendgrid.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21767
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;sendgrid.com. IN A
;; ANSWER SECTION:
SENDGRID.com. 5 IN A 104.20.20.26
SENDGRID.com. 5 IN A 104.20.21.26
The problem here is that due to https://github.com/ruby/ruby/blob/570c028c7ebb18c6d276e5fac3a1b20f76f28db7/lib/resolv.rb#L579, the addresses won't get returned because of the case difference. As a result, Resolv::DNS
sporadically returns no IP addresses. In my example, let's say that I'm calling Resolv::DNS.new.getaddresses("sendgrid.com")
and it returns uppercase. The message returned will be something like this
=> #<Resolv::DNS::Message:0x007f3eff488a88 @id=26224, @qr=1, @opcode=0, @aa=0, @tc=0, @rd=1, @ra=1, @rcode=0, @question=[[#<Resolv::DNS::Name: sendgrid.com.>, Resolv::DNS::Resource::IN::A]], @answer=[[#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47f618 @address=#<Resolv::IPv4 104.20.21.26>, @ttl=1>], [#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47e678 @address=#<Resolv::IPv4 104.20.20.26>, @ttl=1>]], @authority=[], @additional=[]>
whereas "n0" will be
=> #<Resolv::DNS::Name: sendgrid.com.>
so the comparison in line 579 returns false.
Here's another example of this in an irb console on my Rackspace server
require 'resolv'
r = Resolv::DNS.new
10.times { puts r.getaddresses("sendgrid.com").inspect }
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
=> 10
DNS is case-insensitive, so the comparison should be case-insensitive as well.
Updated by jonhyman (Jon Hyman) almost 10 years ago
My pasting got stripped:
Here is the message returned
#<Resolv::DNS::Message:0x007f3eff488a88 @id=26224, @qr=1, @opcode=0, @aa=0, @tc=0, @rd=1, @ra=1, @rcode=0, @question=[[#<Resolv::DNS::Name: sendgrid.com.>, Resolv::DNS::Resource::IN::A]], @answer=[[#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47f618 @address=#<Resolv::IPv4 104.20.21.26>, @ttl=1>], [#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47e678 @address=#<Resolv::IPv4 104.20.20.26>, @ttl=1>]], @authority=[], @additional=[]>
Here is "n0"
=> #<Resolv::DNS::Name: sendgrid.com.>
Here is the output from the 10.times loop.
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
Updated by bjmllr (Ben Miller) almost 10 years ago
I ran into some case-sensitivity issues while using Resolv
as well. A patch to Resolv::DNS::Name#==
seemed to solve it for me.
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Description updated (diff)
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r49073.
resolv.rb: case-insensitive comparison
- lib/resolv.rb (Resolv::DNS::Name#==): DNS is case-insensitive, so the
comparison should be case-insensitive as well.
[ruby-core:66498] [Bug #10550]
Updated by nagachika (Tomoyuki Chikanaga) almost 10 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
Updated by nagachika (Tomoyuki Chikanaga) almost 10 years ago
memo: r49071 and r49072 are similar fixes for resolv.rb
Updated by duerst (Martin Dürst) almost 10 years ago
- Related to Feature #10085: Add non-ASCII case conversion to String#upcase/downcase/swapcase/capitalize added
Updated by usa (Usaku NAKAMURA) almost 10 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: DONE, 2.1: REQUIRED, 2.2: REQUIRED
Backported r49701, r49702, r49703 and r49708 into ruby_2_0_0
at r49252.
Updated by naruse (Yui NARUSE) almost 10 years ago
- Backport changed from 2.0.0: DONE, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: DONE, 2.1: REQUIRED, 2.2: DONE
ruby_2_2 r49281 merged revision(s) 49071,49072,49073,49078.
Updated by nagachika (Tomoyuki Chikanaga) over 9 years ago
- Backport changed from 2.0.0: DONE, 2.1: REQUIRED, 2.2: DONE to 2.0.0: DONE, 2.1: DONE, 2.2: DONE
Backported into ruby_2_1
branch at r49775.