diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-21 03:37:26 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-21 03:37:26 +0000 |
commit | 1ffbe07e179a2e047d24c7091f6ff013195b1a93 (patch) | |
tree | 15566bd714419aee307f263744c9a9d8209ed00b | |
parent | 96225160f6bffb31dea5ab3c75746d415458d4b6 (diff) | |
download | ruby-1ffbe07e179a2e047d24c7091f6ff013195b1a93.tar.gz |
resolv.rb: no encodings
* lib/resolv.rb (Resolv::Hosts#lazy_initialize): should not
consider encodings in hosts file. [ruby-core:59239] [Bug #9273]
* lib/resolv.rb (Resolv::Config.parse_resolv_conf): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/resolv.rb | 4 | ||||
-rw-r--r-- | test/resolv/test_addr.rb | 12 | ||||
-rw-r--r-- | test/resolv/test_dns.rb | 13 |
4 files changed, 34 insertions, 2 deletions
@@ -1,3 +1,10 @@ +Sat Dec 21 12:37:19 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/resolv.rb (Resolv::Hosts#lazy_initialize): should not + consider encodings in hosts file. [ruby-core:59239] [Bug #9273] + + * lib/resolv.rb (Resolv::Config.parse_resolv_conf): ditto. + Sat Dec 21 05:43:27 2013 NAKAMURA Usaku <usa@ruby-lang.org> * tool/make-snapshot: replace RUBY_PATCHLEVEL_STR in version.h to diff --git a/lib/resolv.rb b/lib/resolv.rb index 6d34a67e09..0c2b68ec27 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -187,7 +187,7 @@ class Resolv unless @initialized @name2addr = {} @addr2name = {} - open(@filename) {|f| + open(@filename, 'rb') {|f| f.each {|line| line.sub!(/#.*/, '') addr, hostname, *aliases = line.split(/\s+/) @@ -920,7 +920,7 @@ class Resolv nameserver = [] search = nil ndots = 1 - open(filename) {|f| + open(filename, 'rb') {|f| f.each {|line| line.sub!(/[#;].*/, '') keyword, *args = line.split(/\s+/) diff --git a/test/resolv/test_addr.rb b/test/resolv/test_addr.rb index 84bc8c2d3b..d4728e1b71 100644 --- a/test/resolv/test_addr.rb +++ b/test/resolv/test_addr.rb @@ -13,4 +13,16 @@ class TestResolvAddr < Test::Unit::TestCase end } end + + def test_invalid_byte_comment + bug9273 = '[ruby-core:59239] [Bug #9273]' + Tempfile.open('resolv_test_addr_') do |tmpfile| + tmpfile.print("\xff\x00\x40") + tmpfile.close + hosts = Resolv::Hosts.new(tmpfile.path) + assert_nothing_raised(ArgumentError, bug9273) do + hosts.each_address("") {break} + end + end + end end diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb index 0d9565ef68..e3e38ef555 100644 --- a/test/resolv/test_dns.rb +++ b/test/resolv/test_dns.rb @@ -1,6 +1,7 @@ require 'test/unit' require 'resolv' require 'socket' +require 'tempfile' class TestResolvDNS < Test::Unit::TestCase def setup @@ -150,4 +151,16 @@ class TestResolvDNS < Test::Unit::TestCase } end + def test_invalid_byte_comment + bug9273 = '[ruby-core:59239] [Bug #9273]' + Tempfile.open('resolv_test_dns_') do |tmpfile| + tmpfile.print("\xff\x00\x40") + tmpfile.close + Resolv::DNS.open(tmpfile.path) do |dns| + assert_nothing_raised(ArgumentError, bug9273) do + dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A) + end + end + end + end end |