]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Detect and reject attempts to use compressed names in the generic rdata
authorBob Halley <halley@dnspython.org>
Fri, 21 Aug 2020 16:20:17 +0000 (09:20 -0700)
committerBob Halley <halley@dnspython.org>
Fri, 21 Aug 2020 16:20:17 +0000 (09:20 -0700)
syntax of a known type.

dns/rdata.py
tests/test_rdata.py

index 0d8f881f514291b1d3b2ad096d0b680ce29dff13..a5d3a66a51a2db1d467f1449da502449a63614c9 100644 (file)
@@ -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)
index 0c98760b8b967e05ecb372d98910d1451064f6c1..41465e002a9385d191adab4a0ddd87d199d7ca08 100644 (file)
@@ -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()