dpkt icon indicating copy to clipboard operation
dpkt copied to clipboard

DNS object always has an 'empty' string data field

Open brifordwylie opened this issue 8 years ago • 1 comments

The dns decoder currently uses the data field but at the end sets it to an empty string.

    def unpack(self, buf):
        dpkt.Packet.unpack(self, buf)
        off = self.__hdr_len__
        cnt = self.qd  # FIXME: This relies on this being properly set somewhere else
        self.qd = []
        for _ in range(cnt):
            q, off = self.unpack_q(buf, off)
            self.qd.append(q)
        for x in ('an', 'ns', 'ar'):
            cnt = getattr(self, x, 0)
            setattr(self, x, [])
            for _ in range(cnt):
                rr, off = self.unpack_rr(buf, off)
                getattr(self, x).append(rr)
        self.data = ''

So looks like two options to me:

  1. It's fine, leave it
  2. We should remove the data attribute
  3. Other...

Happy to do any of the above. @kbandla @obormot can pick one :)

brifordwylie avatar Aug 17 '16 03:08 brifordwylie

This looks like a bug/improper coding to me. self.data should be set to leftover bytes remaining after unpacking. If it's fully unpacked then set to an empty string, sure. But the code above just trusts the packet and unpacks it blindly..

obormot avatar Jan 30 '17 06:01 obormot