]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
catch DNSName exceptions in responder thread, possibly preventing death of dnsdist
authorbert hubert <bert.hubert@netherlabs.nl>
Mon, 29 Feb 2016 09:45:33 +0000 (10:45 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Mon, 29 Feb 2016 09:45:33 +0000 (10:45 +0100)
pdns/dnsdist.cc
pdns/dnsdist.hh

index ae636aa6900cae1cf8811c0ad65c633496c396c0..137c3d6c2990d88adcbfd5d79bca29bc4ce67a45 100644 (file)
@@ -202,7 +202,16 @@ void* responderThread(std::shared_ptr<DownstreamState> state)
     */
     ids->age = 0;
     unsigned int consumed;
-    DNSName qname(packet, responseLen, sizeof(dnsheader), false, &qtype, &qclass, &consumed);
+    DNSName qname;
+    try {
+      // XXX will this move?
+      qname=DNSName(packet, responseLen, sizeof(dnsheader), false, &qtype, &qclass, &consumed);
+    }
+    catch(std::exception& e) {
+      infolog("Backend %s sent us a response that did not parse: %s", state->remote.toStringWithPort(), e.what());
+      g_stats.nonCompliantResponses++;
+      continue;
+    }
     if (qtype != ids->qtype || qclass != ids->qclass || qname != ids->qname)
       continue;
 
@@ -537,6 +546,7 @@ const NumberedServerVector& getDownstreamCandidates(const pools_t& pools, const
 
 // goal in life - if you send us a reasonably normal packet, we'll get Z for you, otherwise 0
 int getEDNSZ(const char* packet, unsigned int len)
+try
 {
   struct dnsheader* dh =(struct dnsheader*)packet;
 
@@ -562,6 +572,10 @@ int getEDNSZ(const char* packet, unsigned int len)
   uint8_t* z = (uint8_t*)packet+sizeof(dnsheader)+pos+consumed+DNS_TYPE_SIZE+DNS_CLASS_SIZE+EDNS_EXTENDED_RCODE_SIZE+EDNS_VERSION_SIZE;
   return 0x100 * (*z) + *(z+1);
 }
+catch(...)
+{
+  return 0;
+}
 
 void spoofResponseFromString(DNSQuestion& dq, const string& spoofContent)
 {
index 61ef35daf1f9f84fbac0ce8589666dccf4732b6b..0d5b8f7ab8f746dc64cfef2e0249653f84a2d77a 100644 (file)
@@ -42,6 +42,7 @@ struct DNSDistStats
   stat_t servfailResponses{0};
   stat_t queries{0};
   stat_t nonCompliantQueries{0};
+  stat_t nonCompliantResponses{0};
   stat_t rdQueries{0};
   stat_t emptyQueries{0};
   stat_t aclDrops{0};
@@ -76,6 +77,7 @@ struct DNSDistStats
     {"uptime", uptimeOfProcess},
     {"real-memory-usage", getRealMemoryUsage},
     {"noncompliant-queries", &nonCompliantQueries},
+    {"noncompliant-responses", &nonCompliantResponses},
     {"rdqueries", &rdQueries},
     {"empty-queries", &emptyQueries},
     {"cache-hits", &cacheHits},