Skip to content

Commit 210995b

Browse files
committed
merge revision(s) 44312,44318: [Backport ruby#9273]
* lib/resolv.rb (Resolv::Hosts#lazy_initialize): should not consider encodings in hosts file. [ruby-core:59239] [Bug ruby#9273] * lib/resolv.rb (Resolv::Config.parse_resolv_conf): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent d25384c commit 210995b

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Fri Feb 21 17:42:42 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* lib/resolv.rb (Resolv::Hosts#lazy_initialize): should not
4+
consider encodings in hosts file. [ruby-core:59239] [Bug #9273]
5+
6+
* lib/resolv.rb (Resolv::Config.parse_resolv_conf): ditto.
7+
18
Fri Feb 21 16:47:20 2014 Nobuyoshi Nakada <[email protected]>
29

310
* string.c (get_encoding): respect BOM on pseudo encodings.

lib/resolv.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def lazy_initialize # :nodoc:
187187
unless @initialized
188188
@name2addr = {}
189189
@addr2name = {}
190-
open(@filename) {|f|
190+
open(@filename, 'rb') {|f|
191191
f.each {|line|
192192
line.sub!(/#.*/, '')
193193
addr, hostname, *aliases = line.split(/\s+/)
@@ -920,7 +920,7 @@ def Config.parse_resolv_conf(filename)
920920
nameserver = []
921921
search = nil
922922
ndots = 1
923-
open(filename) {|f|
923+
open(filename, 'rb') {|f|
924924
f.each {|line|
925925
line.sub!(/[#;].*/, '')
926926
keyword, *args = line.split(/\s+/)

test/resolv/test_addr.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@ def test_invalid_ipv4_address
1313
end
1414
}
1515
end
16+
17+
def test_invalid_byte_comment
18+
bug9273 = '[ruby-core:59239] [Bug #9273]'
19+
Tempfile.open('resolv_test_addr_') do |tmpfile|
20+
tmpfile.print("\xff\x00\x40")
21+
tmpfile.close
22+
hosts = Resolv::Hosts.new(tmpfile.path)
23+
assert_nothing_raised(ArgumentError, bug9273) do
24+
hosts.each_address("") {break}
25+
end
26+
end
27+
end
1628
end

test/resolv/test_dns.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'test/unit'
22
require 'resolv'
33
require 'socket'
4+
require 'tempfile'
45

56
class TestResolvDNS < Test::Unit::TestCase
67
def setup
@@ -150,4 +151,14 @@ def test_no_server
150151
}
151152
end
152153

154+
def test_invalid_byte_comment
155+
bug9273 = '[ruby-core:59239] [Bug #9273]'
156+
Tempfile.open('resolv_test_dns_') do |tmpfile|
157+
tmpfile.print("\xff\x00\x40")
158+
tmpfile.close
159+
assert_nothing_raised(ArgumentError, bug9273) do
160+
Resolv::DNS::Config.parse_resolv_conf(tmpfile.path)
161+
end
162+
end
163+
end
153164
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.1"
22
#define RUBY_RELEASE_DATE "2014-02-21"
3-
#define RUBY_PATCHLEVEL 41
3+
#define RUBY_PATCHLEVEL 42
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2

0 commit comments

Comments
 (0)