From: Remi Gacogne Date: Fri, 13 Apr 2018 16:45:41 +0000 (+0200) Subject: rec: Don't copy the UDP query from a buffer to a string X-Git-Tag: dnsdist-1.3.1~129^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04896b99a9efbca56216643d5ce1ccb3555bc58b;p=thirdparty%2Fpdns.git rec: Don't copy the UDP query from a buffer to a string --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index f91e31fefa..78c85174ec 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1985,21 +1985,30 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) { ssize_t len; - char data[1500]; + static thread_local std::string data; ComboAddress fromaddr; struct msghdr msgh; struct iovec iov; char cbuf[256]; bool firstQuery = true; + data.resize(1500); fromaddr.sin6.sin6_family=AF_INET6; // this makes sure fromaddr is big enough - fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), data, sizeof(data), &fromaddr); + fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), &data[0], data.size(), &fromaddr); for(;;) if((len=recvmsg(fd, &msgh, 0)) >= 0) { firstQuery = false; + if (static_cast(len) < sizeof(dnsheader)) { + g_stats.ignoredCount++; + if (!g_quiet) { + g_log<push_back(fromaddr); @@ -2019,7 +2028,8 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) return; } try { - dnsheader* dh=(dnsheader*)data; + data.resize(static_cast(len)); + dnsheader* dh=(dnsheader*)&data[0]; if(dh->qr) { g_stats.ignoredCount++; @@ -2032,7 +2042,6 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) g_log<opcode<<" from "<