From f789de1e6521cdd5ca11917522259a22ed902ab3 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Fri, 21 Aug 2020 09:20:17 -0700 Subject: [PATCH] Detect and reject attempts to use compressed names in the generic rdata syntax of a known type. --- dns/rdata.py | 10 ++++++++++ tests/test_rdata.py | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/dns/rdata.py b/dns/rdata.py index 0d8f881f..a5d3a66a 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -468,6 +468,16 @@ def from_text(rdclass, rdtype, tok, origin=None, relativize=True, relativize, relativize_to) rdata = from_wire(rdclass, rdtype, grdata.data, 0, len(grdata.data), origin) + # + # If this comparison isn't equal, then there must have been + # compressed names in the wire format, which is an error, + # there being no reasonable context to decompress with. + # + rwire = rdata.to_wire() + if rwire != grdata.data: + raise dns.exception.SyntaxError('compressed data in ' + 'generic syntax form ' + 'of known rdatatype') if rdata is None: rdata = cls.from_text(rdclass, rdtype, tok, origin, relativize, relativize_to) diff --git a/tests/test_rdata.py b/tests/test_rdata.py index 0c98760b..41465e00 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -737,6 +737,10 @@ class UtilTestCase(unittest.TestCase): b = dns.rdtypes.util.Bitmap([]) b.from_wire_parser(parser) + def test_compressed_in_generic_is_bad(self): + with self.assertRaises(dns.exception.SyntaxError): + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + r'\# 4 000aC000') if __name__ == '__main__': unittest.main() -- 2.47.3