Project

General

Profile

Bug #11632

Resolv::DNS::Message.encode fails to encode messages larger than 16383 byte

Added by hannes.georg (Hannes Georg) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:71248]

Description

Hello Rubyists

The ruby dns message encoder automatically remembers all label addresses to be reused later ( see https://github.com/ruby/ruby/blob/v2_2_3/lib/resolv.rb#L1470 ). The address field however is limited to 14 bits ( see https://tools.ietf.org/html/rfc1035#section-4.1.4 ). If the message gets larger than 16383 bytes the addresses of new labels won't fit anymore. The encoder takes this into account and truncates the addresses on write which makes them invalid ( see https://github.com/ruby/ruby/blob/v2_2_3/lib/resolv.rb#L1467 ).

My suggested solution is to not store addresses larger than 16383. Is a github pr okay for that?

Updated by hannes.georg (Hannes Georg) about 5 years ago

I've created a small script to demonstrate the behavior. The following script should print "test" but it prints some gibberish bytes in ruby 2.1.7 and 2.2.3.

require 'resolv'

msg = Resolv::DNS::Message.new
# this generates ~ 17000 bytes
500.times.each do |i|
  msg.add_answer("abcdefghijklmn%04d." % i,300,Resolv::DNS::Resource::IN::A.new("0.0.0.0"))
end
msg.add_answer("test.",300,Resolv::DNS::Resource::IN::A.new("0.0.0.0"))
msg.add_answer("test.",300,Resolv::DNS::Resource::IN::A.new("0.0.0.0"))
encoded = msg.encode
decoded = Resolv::DNS::Message.decode(encoded)
puts decoded.answer.last[0].to_s.inspect
#3

Updated by akr (Akira Tanaka) about 5 years ago

  • Status changed from Open to Closed

Applied in changeset r52508.


  • lib/resolv.rb (Resolv::DNS::Message::MessageEncoder#put_labels): Prevent overflow of pointer to labels. Patch by Hannes Georg. [ruby-core:71248] [Bug #11632]

Also available in: Atom PDF