From: Bob Halley Date: Tue, 6 Aug 2024 21:46:49 +0000 (-0700) Subject: Do not allow an empty list in TXT record wire format or by invoking the constructor... X-Git-Tag: v2.7.0rc1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=720b2734b8d103908d22fec6aad6d8ac6cd7e5ee;p=thirdparty%2Fdnspython.git Do not allow an empty list in TXT record wire format or by invoking the constructor. (#1118) [#1117] --- 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):