From 1d705e71ba0c2fcc91d09d60c4d8509b38ccad7f Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 15 Sep 2020 16:33:07 +0200 Subject: [PATCH] dnsdist: Only copy what we need from the response buffer --- pdns/dnsdist-tcp.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index e3e8d88ce3..f1383a0d09 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -323,7 +323,6 @@ static IOState handleResponseSent(std::shared_ptr& s } } - bool IncomingTCPConnectionState::canAcceptNewQueries() const { if (d_isXFR) { @@ -573,10 +572,13 @@ static bool handleQuery(std::shared_ptr& 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(&state->d_buffer.at(0)); - dq.size = state->d_buffer.size(); state->d_buffer.resize(dq.len); bool proxyProtocolPayloadAdded = false; -- 2.47.3