From e415d84205757864abf471674a2629d783f5089e Mon Sep 17 00:00:00 2001 From: bert hubert Date: Mon, 29 Feb 2016 12:27:01 +0100 Subject: [PATCH] improve error message on unparseable responses from backend, and also do not log about empty packets --- pdns/dnsdist.cc | 3 ++- pdns/dnsname.cc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 995a893e0..042c9162f 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -207,7 +207,8 @@ void* responderThread(std::shared_ptr state) 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()); + if(got > (ssize_t)sizeof(dnsheader)) + infolog("Backend %s sent us a response with id %d that did not parse: %s", state->remote.toStringWithPort(), ntohs(dh->id), e.what()); g_stats.nonCompliantResponses++; continue; } diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 94f7c542a..2b1d269c6 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -60,7 +60,7 @@ DNSName::DNSName(const char* p) DNSName::DNSName(const char* pos, int len, int offset, bool uncompress, uint16_t* qtype, uint16_t* qclass, unsigned int* consumed) { if (offset >= len) - throw std::range_error("Trying to read past the end of the buffer"); + throw std::range_error("Trying to read past the end of the buffer ("+std::to_string(offset)+ " >= "+std::to_string(len)+")"); if(!uncompress) { if(const void * fnd=memchr(pos+offset, 0, len-offset)) { @@ -79,7 +79,7 @@ void DNSName::packetParser(const char* qpos, int len, int offset, bool uncompres const unsigned char *opos = pos; if (offset >= len) - throw std::range_error("Trying to read past the end of the buffer"); + throw std::range_error("Trying to read past the end of the buffer ("+std::to_string(offset)+ " >= "+std::to_string(len)+")"); pos += offset; const unsigned char* end = pos + len; -- 2.40.0