From: Bob Halley Date: Mon, 21 Dec 2020 15:11:30 +0000 (-0800) Subject: resolve_chaining() should not go into an infinite loop if the qtype is X-Git-Tag: v2.1.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cadb332e9946fb404fe70a0ba2775733f6a6824;p=thirdparty%2Fdnspython.git resolve_chaining() should not go into an infinite loop if the qtype is CNAME and there is no answer [Issue #610]. --- diff --git a/dns/message.py b/dns/message.py index 9824e700..5c35dbc7 100644 --- a/dns/message.py +++ b/dns/message.py @@ -776,6 +776,9 @@ class QueryMessage(Message): except KeyError: # Exit the chaining loop break + else: + # Exit the chaining loop + break if count >= MAX_CHAIN: raise ChainTooLong if self.rcode() == dns.rcode.NXDOMAIN and rrset is not None: diff --git a/tests/test_message.py b/tests/test_message.py index 8ebcd054..ec964584 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -550,6 +550,20 @@ class MessageTestCase(unittest.TestCase): with self.assertRaises(dns.exception.FormError): r.resolve_chaining() + def test_resolve_chaining_no_infinite_loop(self): + r = dns.message.from_text('''id 1 +flags QR +;QUESTION +www.example. IN CNAME +;AUTHORITY +example. 300 IN SOA . . 1 2 3 4 5 +''') + # passing is actuall not going into an infinite loop in this call + (qname, min_ttl, rrset) = r.resolve_chaining() + self.assertEqual(qname, dns.name.from_text('www.example.')) + self.assertEqual(min_ttl, 5) + self.assertIsNone(rrset) + def test_bad_text_questions(self): with self.assertRaises(dns.exception.SyntaxError): dns.message.from_text('''id 1