From 720b2734b8d103908d22fec6aad6d8ac6cd7e5ee Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Tue, 6 Aug 2024 14:46:49 -0700 Subject: [PATCH] Do not allow an empty list in TXT record wire format or by invoking the constructor. (#1118) [#1117] --- dns/rdtypes/txtbase.py | 2 ++ tests/test_rdata.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/dns/rdtypes/txtbase.py b/dns/rdtypes/txtbase.py index 3e35b140..73db6d9e 100644 --- a/dns/rdtypes/txtbase.py +++ b/dns/rdtypes/txtbase.py @@ -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, diff --git a/tests/test_rdata.py b/tests/test_rdata.py index 38ff8317..c63dc18c 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -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): -- 2.47.3