From b2dac7593f03793f7695a8e137d26a0a25140b44 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Wed, 18 Jun 2014 16:13:39 -0700 Subject: [PATCH] Allow empty APL RR. --- ChangeLog | 6 ++++++ dns/rdtypes/IN/APL.py | 4 ++-- tests/test_bugs.py | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ee3bf73..fcf2f821 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-06-18 Bob Halley + + * dns/rdtypes/IN/APL.py: The APL from_wire() method did not accept an + rdata length of 0 as valid. Thanks to salzmdan for reporting the + problem. + 2014-05-31 Bob Halley * dns/ipv6.py: Add is_mapped() diff --git a/dns/rdtypes/IN/APL.py b/dns/rdtypes/IN/APL.py index 260fd6f3..59da75b9 100644 --- a/dns/rdtypes/IN/APL.py +++ b/dns/rdtypes/IN/APL.py @@ -118,6 +118,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]) @@ -151,8 +153,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/test_bugs.py b/tests/test_bugs.py index 312ec3ef..cee87575 100644 --- a/tests/test_bugs.py +++ b/tests/test_bugs.py @@ -45,5 +45,12 @@ class BugsTestCase(unittest.TestCase): "1 0 100 ABCD SCBCQHKU35969L2A68P3AD59LHF30715") self.failUnless(rdata.windows == []) + 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, + "", 0, 0) + self.failUnless(rdata == rdata2) + if __name__ == '__main__': unittest.main() -- 2.47.3