Project

General

Profile

Bug #10412

DNS Resolv broken when resolv.conf has option ndots > 1

Added by vo.x (Vit Ondruch) over 4 years ago. Updated over 4 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:65836]

Description

This was originally reported by Frank Hirtz at Red Hat's Bugzilla:

https://bugzilla.redhat.com/show_bug.cgi?id=1132704

Description of problem:
Rubys resolver (/usr/lib/ruby/1.8/resolv.rb) attempts to implement name canonicalization similar to the system resolver.

It's implementation prevents simple lookups when ndots is set greater than 1 (the default).

For example, with this resolv.conf:

    nameserver 192.168.1.1
    nameserver 192.168.1.2
    options ndots:2
    search a.example.com b.example.com example.com

This script raises an Resolv::ResolvError exception:

    #!/usr/bin/ruby
    require 'resolv'
    p Resolv.getaddress('google.com')


Ruby's resolver parses /etc/resolv.conf extracting nameservers, search domains, and the ndots option.

When you attempt to resolv a name (which does not include a trailing "." indicating it is already fully qualified) it determines the number of dots in the name, and if there number of dots in the name is less than the ndots option, it attempts canonicalization.

This is correct behavior, but the canonicalization mechanism is where the problem lies. In the above example, it performs three lookups: google.com.a.example.com, google.com.b.example.com, and google.com.example.com. 

The linux resolver would do the same, and then fail back to google.com. if canonicalization fails. The issue is in /usr/lib/ruby/1.8/resolv.rb. The following patch makes ruby's resolver behave the same way as the system resolver:

    --- /usr/lib/ruby/1.8/resolv.rb 2010-12-22 22:22:57.000000000 -0500
    +++ resolv.rb   2014-08-20 18:50:05.653882000 -0400
    @@ -945,6 +945,10 @@
                 candidates = []
               end
               candidates.concat(@search.map {|domain| Name.new(name.to_a + domain)})
    +          fname = Name.create("#{name}.")
    +          if !candidates.include?(fname)
    +              candidates << fname
    +          end
             end
             return candidates
           end

It looks like the same bug exists in the upstream stable ruby 2.1.2.

This issue causes the client see failures in their configuration management system (puppet) and home-grown host provisioning system.

Version-Release number of selected component (if applicable):
All (RHEL versions as well as upstream). Tested on ruby and ruby200 in RHEL6 and Ruby 2.x in fedora.

Associated revisions

Revision e6a5f817
Added by usa (Usaku NAKAMURA) over 4 years ago

merge revision(s) 48534: [Backport #10412]

    * lib/resolv.rb: fall back if canonicalization fails.
      Thanks Vit Ondruch for the patch!  [ruby-core:65836]

    * test/resolv/test_dns.rb: test for patch

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@49245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 49245
Added by usa (Usaku NAKAMURA) over 4 years ago

merge revision(s) 48534: [Backport #10412]

* lib/resolv.rb: fall back if canonicalization fails.
  Thanks Vit Ondruch for the patch!  [ruby-core:65836]

* test/resolv/test_dns.rb: test for patch

Revision 00a360a9
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

merge revision(s) r48534: [Backport #10412]

    * lib/resolv.rb: fall back if canonicalization fails.
      Thanks Vit Ondruch for the patch!  [ruby-core:65836]

    * test/resolv/test_dns.rb: test for patch

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@49471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 49471
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

merge revision(s) r48534: [Backport #10412]

* lib/resolv.rb: fall back if canonicalization fails.
  Thanks Vit Ondruch for the patch!  [ruby-core:65836]

* test/resolv/test_dns.rb: test for patch

History

Updated by fmhirtz (Frank Hirtz) over 4 years ago

Hi,

This should be a simple fix with the noted patch; is it possible for someone to have a look and see if it's fit for inclusion?

Thank you!

Updated by tenderlovemaking (Aaron Patterson) over 4 years ago

  • Status changed from Open to Closed

This should be fixed in r48534. Thanks!

Updated by vo.x (Vit Ondruch) over 4 years ago

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

Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: DONE, 2.1: REQUIRED

Backported into ruby_2_0_0 at r49245.

Updated by nagachika (Tomoyuki Chikanaga) over 4 years ago

  • Backport changed from 2.0.0: DONE, 2.1: REQUIRED to 2.0.0: DONE, 2.1: DONE

Backported into ruby_2_1 at r49471.

Also available in: Atom PDF