dnslib
dnslib copied to clipboard
Records with empty rdata causes pack() to fail
A DNSRecord instance such as
<DNS Header: id=0x9d1a type=QUERY opcode=UPDATE flags= rcode='NOERROR' zo=1 pr=1 up=3 ad=0>
<DNS Question: 'xxx.net.' qtype=SOA qclass=IN>
<DNS RR: 'yyy.xxx.net.' rtype=CNAME rclass=None ttl=0 rdata=''>
<DNS RR: 'yyy.xxx.net.' rtype=AAAA rclass=* ttl=0 rdata=''>
<DNS RR: 'yyy.xxx.net.' rtype=A rclass=* ttl=0 rdata=''>
<DNS RR: 'yyy.xxx.net.' rtype=A rclass=IN ttl=1200 rdata='192.168.1.2'>
will fail to pack() with the following error:
>>> r.pack()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/peter/.local/lib/python3.12/site-packages/dnslib/dns.py", line 335, in pack
rr.pack(buffer)
File "/home/peter/.local/lib/python3.12/site-packages/dnslib/dns.py", line 888, in pack
self.rdata.pack(buffer)
^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'pack'
I believe the source of the error is https://github.com/paulc/dnslib/blob/724f94e52cbc030211d0f86b2271aa2f4874d704/dnslib/dns.py#L831