dpkt
dpkt copied to clipboard
DNS object always has an 'empty' string data field
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:
- It's fine, leave it
- We should remove the data attribute
- Other...
Happy to do any of the above. @kbandla @obormot can pick one :)
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..