]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
even on errors where we tolerate no question, check question if present
authorBob Halley <halley@dnspython.org>
Sat, 25 Jul 2020 13:29:08 +0000 (06:29 -0700)
committerBob Halley <halley@dnspython.org>
Sat, 25 Jul 2020 13:29:08 +0000 (06:29 -0700)
dns/message.py
tests/test_message.py

index ab3de5b16113e28c79cc06d546af2bc2d9a332a8..bc4cced19cbd24992e4751c80585f0d836845df5 100644 (file)
@@ -248,9 +248,11 @@ class Message:
             return False
         if other.rcode() in {dns.rcode.FORMERR, dns.rcode.SERVFAIL,
                              dns.rcode.NOTIMP, dns.rcode.REFUSED}:
-            # We don't check the question section in these cases, even
-            # though they still ought to have the same question.
-            return True
+            # We don't check the question section in these cases if
+            # the other question section is empty, even though they
+            # still really ought to have a question section.
+            if len(other.question) == 0:
+                return True
         if dns.opcode.is_update(self.flags):
             # This is assuming the "sender doesn't include anything
             # from the update", but we don't care to check the other
index bfc137fdd14da06dd7882c1246a62a986657e905..f004b928cf747feca2188b39a9a5161fc2b5e96b 100644 (file)
@@ -368,6 +368,13 @@ class MessageTestCase(unittest.TestCase):
         q.additional = [rrset]
         self.assertEqual(q.sections[3], [rrset])
 
+    def test_is_a_response_empty_question(self):
+        q = dns.message.make_query('www.dnspython.org.', 'a')
+        r = dns.message.make_response(q)
+        r.question = []
+        r.set_rcode(dns.rcode.FORMERR)
+        self.assertTrue(q.is_response(r))
+
     def test_not_a_response(self):
         q = dns.message.QueryMessage(id=1)
         self.assertFalse(q.is_response(q))
@@ -384,6 +391,11 @@ class MessageTestCase(unittest.TestCase):
         q2.id = 1
         r = dns.message.make_response(q2)
         self.assertFalse(q1.is_response(r))
+        # Now set rcode to FORMERR and check again.  It should still
+        # not be a response as we check the question section for FORMERR
+        # if it is present.
+        r.set_rcode(dns.rcode.FORMERR)
+        self.assertFalse(q1.is_response(r))
         # Test the other case of differing questions, where there is
         # something in the response's question section that is not in
         # the question's.  We have to do multiple questions to test