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

 
1
# Resolver monkey patch to bail correctly on truncated UDP responses
2
class Resolv
3
  class DNS
4
    # Monkey patch
5
    class Message
6
      # Alias class method
7
      singleton_class.send(:alias_method, :_decode, :decode)
8
      # Wrap
9
      def self.decode(m)
10
        o = Message.new(0)
11
        MessageDecoder.new(m.dup) {|msg|
12
          id, flag = msg.get_unpack('nn')
13
          # ID is needed to avoid retry
14
          o.id = id
15
          # TC and flag are necessary within fetch_resource
16
          # for TCP failover to happen
17
          o.tc = (flag >> 9) & 1
18
          o.rcode = flag & 15
19
        }
20
        # Bail early on truncation
21
        return o unless o.tc.zero?
22
        # Otherwise use original
23
        Message._decode(m)
24
      end
25
    end
26
  end
27
end