From: Bob Halley Date: Sat, 25 Jul 2020 13:29:08 +0000 (-0700) Subject: even on errors where we tolerate no question, check question if present X-Git-Tag: v2.1.0rc1~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55ab7215cfc2300410deeda60beff5eedcebdcad;p=thirdparty%2Fdnspython.git even on errors where we tolerate no question, check question if present --- diff --git a/dns/message.py b/dns/message.py index ab3de5b1..bc4cced1 100644 --- a/dns/message.py +++ b/dns/message.py @@ -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 diff --git a/tests/test_message.py b/tests/test_message.py index bfc137fd..f004b928 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -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