Project

General

Profile

Bug #13513 ยป resolv-monkey-tc.rb

Monkey patch for issue. See detail of description for actual problem. - iamasmith (Andrew Smith), 04/26/2017 04:12 PM

 
# Resolver monkey patch to bail correctly on truncated UDP responses
class Resolv
class DNS
# Monkey patch
class Message
# Alias class method
singleton_class.send(:alias_method, :_decode, :decode)
# Wrap
def self.decode(m)
o = Message.new(0)
MessageDecoder.new(m.dup) {|msg|
id, flag = msg.get_unpack('nn')
# ID is needed to avoid retry
o.id = id
# TC and flag are necessary within fetch_resource
# for TCP failover to happen
o.tc = (flag >> 9) & 1
o.rcode = flag & 15
}
# Bail early on truncation
return o unless o.tc.zero?
# Otherwise use original
Message._decode(m)
end
end
end
end
    (1-1/1)