Project

General

Profile

Bug #10550

Resolv::DNS.getaddresses returns no IPs when nameserver returns in differing case than query

Added by jonhyman (Jon Hyman) over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
[ruby-core:66498]

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.


Related issues

Related to CommonRuby - Feature #10085: Add non-ASCII case conversion to String#upcase/downcase/swapcase/capitalize Open

Associated revisions

Revision 49073
Added by nobu (Nobuyoshi Nakada) over 2 years ago

resolv.rb: case-insensitive comparison

  • lib/resolv.rb (Resolv::DNS::Name#==): DNS is case-insensitive, so the comparison should be case-insensitive as well. [Bug #10550]

Revision 49073
Added by nobu (Nobuyoshi Nakada) over 2 years ago

resolv.rb: case-insensitive comparison

  • lib/resolv.rb (Resolv::DNS::Name#==): DNS is case-insensitive, so the comparison should be case-insensitive as well. [Bug #10550]

Revision 49073
Added by nobu (Nobuyoshi Nakada) over 2 years ago

resolv.rb: case-insensitive comparison

  • lib/resolv.rb (Resolv::DNS::Name#==): DNS is case-insensitive, so the comparison should be case-insensitive as well. [Bug #10550]

Revision 49281
Added by naruse (Yui NARUSE) over 2 years ago

merge revision(s) 49071,49072,49073,49078: [Backport #10550]

* lib/resolv.rb (Resolv::DNS::Name): names with different dots
  should be different.

* lib/resolv.rb (Resolv::DNS::Name#==): DNS is case-insensitive, so the
  comparison should be case-insensitive as well.
   [Bug #10550]

* lib/resolv.rb (Resolv::DNS::Name#==): Compare an array of Label:Str
  objects.  Label#Str#== is case-insensitive.

Revision 49775
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) r49071,r49072,r49073,r49078: [Backport #10550]

* lib/resolv.rb (Resolv::DNS::Name): names with different dots
  should be different.

* lib/resolv.rb (Resolv::DNS::Name#==): DNS is case-insensitive, so the
  comparison should be case-insensitive as well.
   [Bug #10550]

* lib/resolv.rb (Resolv::DNS::Name#==): Compare an array of Label:Str
  objects.  Label#Str#== is case-insensitive.

History

#1 [ruby-core:66499] Updated by jonhyman (Jon Hyman) over 2 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>]

#2 [ruby-core:67209] Updated by bjmllr (Ben Miller) over 2 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.

https://github.com/ruby/ruby/pull/801

#3 [ruby-core:67223] Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Description updated (diff)

#4 [ruby-core:67224] Updated by nobu (Nobuyoshi Nakada) over 2 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. [Bug #10550]

#5 [ruby-core:67228] Updated by nagachika (Tomoyuki Chikanaga) over 2 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED

#6 [ruby-core:67229] Updated by nagachika (Tomoyuki Chikanaga) over 2 years ago

memo: r49071 and r49072 are similar fixes for resolv.rb

#7 [ruby-core:67245] Updated by duerst (Martin Dürst) over 2 years ago

  • Related to Feature #10085: Add non-ASCII case conversion to String#upcase/downcase/swapcase/capitalize added

#8 [ruby-core:67582] Updated by usa (Usaku NAKAMURA) over 2 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.

#9 [ruby-core:67624] Updated by naruse (Yui NARUSE) over 2 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.

#10 [ruby-core:68340] Updated by nagachika (Tomoyuki Chikanaga) about 2 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.

Also available in: Atom PDF