From 25b991d4b737ef458471ebf8d4a5bfea901a2a4c Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sat, 24 Oct 2015 16:25:45 +0200 Subject: [PATCH] massive speedup in dnsparser getName() which previously copied the entire packet twice to fake a header we didn't use --- pdns/dnsparser.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index b2b67b4f5..5b2b9faee 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -413,15 +413,19 @@ uint8_t PacketReader::get8BitInt() DNSName PacketReader::getName() { unsigned int consumed; - vector content(d_content); - content.insert(content.begin(), sizeof(dnsheader), 0); - try { - DNSName dn((const char*) content.data(), content.size(), d_pos + sizeof(dnsheader), true /* uncompress */, 0 /* qtype */, 0 /* qclass */, &consumed); + DNSName dn((const char*) d_content.data() - 12, d_content.size() + 12, d_pos + sizeof(dnsheader), true /* uncompress */, 0 /* qtype */, 0 /* qclass */, &consumed); + // the -12 fakery is because we don't have the header in 'd_content', but we do need to get + // the internal offsets to work d_pos+=consumed; return dn; } + catch(std::range_error& re) + { + throw std::out_of_range(string("dnsname issue: ")+re.what()); + } + catch(...) { throw std::out_of_range("dnsname issue"); -- 2.40.0