mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Made #decode_rdata client to catch errors
* lib/resolv.rb (Resolv::DNS::Message::MessageDecoder#get_rr): re-raise an exception from decode_rdata as DecodeError, so it can report them to the top in more informative way. It was not reflecting on errors of data and thus breaking. Client code expects `DecodeError` and knows how to handle broken messages. [Fix GH-1511] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
af5eae4332
commit
2b2450ba4b
2 changed files with 22 additions and 1 deletions
|
@ -1635,7 +1635,13 @@ class Resolv
|
|||
name = self.get_name
|
||||
type, klass, ttl = self.get_unpack('nnN')
|
||||
typeclass = Resource.get_class(type, klass)
|
||||
res = self.get_length16 { typeclass.decode_rdata self }
|
||||
res = self.get_length16 do
|
||||
begin
|
||||
typeclass.decode_rdata self
|
||||
rescue => e
|
||||
raise DecodeError, e.message, e.backtrace
|
||||
end
|
||||
end
|
||||
res.instance_variable_set :@ttl, ttl
|
||||
return name, ttl, res
|
||||
end
|
||||
|
|
|
@ -205,6 +205,21 @@ class TestResolvDNS < Test::Unit::TestCase
|
|||
assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1:127.0.0.1')
|
||||
end
|
||||
|
||||
def test_ipv6_should_be_16
|
||||
ref = '[rubygems:1626]'
|
||||
|
||||
broken_message =
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\1" \
|
||||
"\x03ns2\bdnsimple\x03com\x00" \
|
||||
"\x00\x1C\x00\x01\x00\x02OD" \
|
||||
"\x00\x10$\x00\xCB\x00 I\x00\x01\x00\x00\x00\x00"
|
||||
|
||||
e = assert_raise_with_message(Resolv::DNS::DecodeError, /IPv6 address must be 16 bytes/, ref) do
|
||||
Resolv::DNS::Message.decode broken_message
|
||||
end
|
||||
assert_kind_of(ArgumentError, e.cause)
|
||||
end
|
||||
|
||||
def test_too_big_label_address
|
||||
n = 2000
|
||||
m = Resolv::DNS::Message::MessageEncoder.new {|msg|
|
||||
|
|
Loading…
Reference in a new issue