]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Do not allow an empty list in TXT record wire format or by invoking the constructor...
authorBob Halley <halley@dnspython.org>
Tue, 6 Aug 2024 21:46:49 +0000 (14:46 -0700)
committerGitHub <noreply@github.com>
Tue, 6 Aug 2024 21:46:49 +0000 (14:46 -0700)
[#1117]

dns/rdtypes/txtbase.py
tests/test_rdata.py

index 3e35b1400f5ef092116a0e8098ff4e42ea0914e0..73db6d9e25dcadab2dacb57001b490ac91d40dba 100644 (file)
@@ -50,6 +50,8 @@ class TXTBase(dns.rdata.Rdata):
         self.strings: Tuple[bytes] = self._as_tuple(
             strings, lambda x: self._as_bytes(x, True, 255)
         )
+        if len(self.strings) == 0:
+            raise ValueError("the list of strings must not be empty")
 
     def to_text(
         self,
index 38ff8317d71b4dafc91055d6624a0006936500af..c63dc18c7ac3ce01a5197835c78b426026cab79f 100644 (file)
@@ -672,6 +672,10 @@ class RdataTestCase(unittest.TestCase):
         with self.assertRaises(dns.exception.SyntaxError):
             dns.rdata.from_text("in", "txt", "")
 
+    def test_empty_TXT_wire(self):
+        with self.assertRaises(dns.exception.FormError):
+            dns.rdata.from_wire(dns.rdataclass.IN, dns.rdatatype.TXT, b"", 0, 0)
+
     def test_too_long_TXT(self):
         # hit too long
         with self.assertRaises(dns.exception.SyntaxError):