From: Bob Halley Date: Mon, 1 Sep 2014 00:14:05 +0000 (-0700) Subject: Allow empty APL RR. X-Git-Tag: v1.12.0-py3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e758ab4e7513f359e6deaf5725dcdd4ffa007d9a;p=thirdparty%2Fdnspython.git Allow empty APL RR. --- diff --git a/dns/rdtypes/IN/APL.py b/dns/rdtypes/IN/APL.py index a7b8510d..58e35b66 100644 --- a/dns/rdtypes/IN/APL.py +++ b/dns/rdtypes/IN/APL.py @@ -119,6 +119,8 @@ class APL(dns.rdata.Rdata): def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): items = [] while 1: + if rdlen == 0: + break if rdlen < 4: raise dns.exception.FormError header = struct.unpack('!HBB', wire[current : current + 4]) @@ -152,8 +154,6 @@ class APL(dns.rdata.Rdata): rdlen -= afdlen item = APLItem(header[0], negation, address, header[1]) items.append(item) - if rdlen == 0: - break return cls(rdclass, rdtype, items) from_wire = classmethod(from_wire) diff --git a/tests/bugs.py b/tests/bugs.py index 79b30eb6..906e0fd8 100644 --- a/tests/bugs.py +++ b/tests/bugs.py @@ -52,5 +52,13 @@ class BugsTestCase(unittest.TestCase): out4 = rd4.to_digestable(dns.name.from_text("test")) self.assertTrue(binascii.hexlify(out4).decode('ascii') == '000101817f') + def test_zero_size_APL(self): + rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.APL, + "") + rdata2 = dns.rdata.from_wire(dns.rdataclass.IN, dns.rdatatype.APL, + b"", 0, 0) + self.assertTrue(rdata == rdata2) + + if __name__ == '__main__': unittest.main()