[前][次][番号順一覧][スレッド一覧]

ruby-changes:32233

From: nobu <ko1@a...>
Date: Sat, 21 Dec 2013 12:37:34 +0900 (JST)
Subject: [ruby-changes:32233] nobu:r44312 (trunk): resolv.rb: no encodings

nobu	2013-12-21 12:37:26 +0900 (Sat, 21 Dec 2013)

  New Revision: 44312

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44312

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/resolv.rb
    trunk/test/resolv/test_addr.rb
    trunk/test/resolv/test_dns.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44311)
+++ ChangeLog	(revision 44312)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 21 12:37:19 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* tool/make-snapshot: replace RUBY_PATCHLEVEL_STR in version.h to
Index: lib/resolv.rb
===================================================================
--- lib/resolv.rb	(revision 44311)
+++ lib/resolv.rb	(revision 44312)
@@ -187,7 +187,7 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L187
         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 https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L920
         nameserver = []
         search = nil
         ndots = 1
-        open(filename) {|f|
+        open(filename, 'rb') {|f|
           f.each {|line|
             line.sub!(/[#;].*/, '')
             keyword, *args = line.split(/\s+/)
Index: test/resolv/test_dns.rb
===================================================================
--- test/resolv/test_dns.rb	(revision 44311)
+++ test/resolv/test_dns.rb	(revision 44312)
@@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/test/resolv/test_dns.rb#L1
 require 'test/unit'
 require 'resolv'
 require 'socket'
+require 'tempfile'
 
 class TestResolvDNS < Test::Unit::TestCase
   def setup
@@ -150,4 +151,16 @@ class TestResolvDNS < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/resolv/test_dns.rb#L151
     }
   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
Index: test/resolv/test_addr.rb
===================================================================
--- test/resolv/test_addr.rb	(revision 44311)
+++ test/resolv/test_addr.rb	(revision 44312)
@@ -13,4 +13,16 @@ class TestResolvAddr < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/resolv/test_addr.rb#L13
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]