]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Report opcode mismatch
authorMark Andrews <marka@isc.org>
Wed, 11 Mar 2020 02:55:14 +0000 (13:55 +1100)
committerMark Andrews <marka@isc.org>
Fri, 13 Mar 2020 01:17:21 +0000 (12:17 +1100)
(cherry picked from commit bb7576cc9bbb98c75f3783dbb6f47bdba2516c20)

bin/dig/dighost.c

index 77a17c88c0566c400f953f3481d47a4d930526b8..61b00b007681c67bf6f4781147fe4ee89544050a 100644 (file)
@@ -60,6 +60,7 @@
 #include <dns/log.h>
 #include <dns/message.h>
 #include <dns/name.h>
+#include <dns/opcode.h>
 #include <dns/rcode.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
@@ -4017,6 +4018,33 @@ recv_done(isc_task_t *task, isc_event_t *event) {
                UNLOCK_LOOKUP;
                return;
        }
+       if (msg->opcode != l->opcode) {
+               isc_buffer_t bb;
+               char expect[20] = { 0 }, got[20] = { 0 };
+
+               isc_buffer_init(&bb, &expect, sizeof(expect));
+               result = dns_opcode_totext(l->opcode, &bb);
+               check_result(result, "dns_opcode_totext");
+
+               isc_buffer_init(&bb, &got, sizeof(got));
+               result = dns_opcode_totext(msg->opcode, &bb);
+               check_result(result, "dns_opcode_totext");
+
+               printf(";; Warning: Opcode mismatch: expected %s, got %s",
+                      expect, got);
+
+               dns_message_destroy(&msg);
+               if (l->tcp_mode) {
+                       isc_event_free(&event);
+                       clear_query(query);
+                       cancel_lookup(l);
+                       check_next_lookup(l);
+                       UNLOCK_LOOKUP;
+                       return;
+               } else {
+                       goto udp_mismatch;
+               }
+       }
        if (msg->counts[DNS_SECTION_QUESTION] != 0) {
                match = true;
                for (result = dns_message_firstname(msg, DNS_SECTION_QUESTION);