diff options
-rw-r--r-- | lib/resolv.rb | 8 | ||||
-rw-r--r-- | test/resolv/test_dns.rb | 15 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/resolv.rb b/lib/resolv.rb index a5a997a43d..ebb2a9c411 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -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 diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb index d1431c1427..f21a094b20 100644 --- a/test/resolv/test_dns.rb +++ b/test/resolv/test_dns.rb @@ -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| |