]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Only copy what we need from the response buffer
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 15 Sep 2020 14:33:07 +0000 (16:33 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 10 Nov 2020 08:52:23 +0000 (09:52 +0100)
pdns/dnsdist-tcp.cc

index e3e8d88ce3178a42e3b2dda790676c11d0363d67..f1383a0d09baa56362a9fdb4fa7a3d02e81eca8e 100644 (file)
@@ -323,7 +323,6 @@ static IOState handleResponseSent(std::shared_ptr<IncomingTCPConnectionState>& s
   }
 }
 
-
 bool IncomingTCPConnectionState::canAcceptNewQueries() const
 {
   if (d_isXFR) {
@@ -573,10 +572,13 @@ static bool handleQuery(std::shared_ptr<IncomingTCPConnectionState>& state, cons
   /* prepend the size. Yes, this is not the most efficient way but it prevents mistakes
      that could occur if we had to deal with the size during the processing,
      especially alignment issues */
+  /* first we need to resize to the size that is actually used, since we allocated more to be able to insert
+     EDNS or Proxy Protocol values */
+  dq.size = state->d_buffer.size();
+  state->d_buffer.resize(dq.len);
   state->d_buffer.insert(state->d_buffer.begin(), sizeBytes, sizeBytes + 2);
   dq.len = dq.len + 2;
   dq.dh = reinterpret_cast<dnsheader*>(&state->d_buffer.at(0));
-  dq.size = state->d_buffer.size();
   state->d_buffer.resize(dq.len);
 
   bool proxyProtocolPayloadAdded = false;