aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-14 02:26:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-14 02:26:48 +0000
commit2b2450ba4bee563e33af0325b7fde8cb1bfd6899 (patch)
tree4a868d34871ebc8b83171fb8455099827e0b7ead
parentaf5eae433239cfabeed4d11ab541f59c99968fb7 (diff)
downloadruby-2b2450ba4bee563e33af0325b7fde8cb1bfd6899.tar.gz
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
-rw-r--r--lib/resolv.rb8
-rw-r--r--test/resolv/test_dns.rb15
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|