From: Remi Gacogne Date: Tue, 26 Oct 2021 13:23:55 +0000 (+0200) Subject: dnsdist: Don't copy the header twice when editing the ID X-Git-Tag: rec-4.6.0-beta1~28^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6dd15988a4b1e5a0a6d05fc80a2a1542338a8338;p=thirdparty%2Fpdns.git dnsdist: Don't copy the header twice when editing the ID As suggested by Otto. --- diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 0ec6ea5d23..30a065441b 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -147,10 +147,8 @@ static void editPayloadID(PacketBuffer& payload, uint16_t newId, size_t proxyPro if (payload.size() < startOfHeaderOffset + sizeof(dnsheader)) { throw std::runtime_error("Invalid buffer for outgoing TCP query (size " + std::to_string(payload.size())); } - dnsheader dh; - memcpy(&dh, &payload.at(startOfHeaderOffset), sizeof(dh)); - dh.id = htons(newId); - memcpy(&payload.at(startOfHeaderOffset), &dh, sizeof(dh)); + uint16_t id = htons(newId); + memcpy(&payload.at(startOfHeaderOffset), &id, sizeof(id)); } enum class QueryState : uint8_t { @@ -689,9 +687,9 @@ uint16_t TCPConnectionToBackend::getQueryIdFromResponse() const throw std::runtime_error("Unable to get query ID in a too small (" + std::to_string(d_responseBuffer.size()) + ") response from " + d_ds->getNameWithAddr()); } - dnsheader dh; - memcpy(&dh, &d_responseBuffer.at(0), sizeof(dh)); - return ntohs(dh.id); + uint16_t id; + memcpy(&id, &d_responseBuffer.at(0), sizeof(id)); + return ntohs(id); } void TCPConnectionToBackend::setProxyProtocolValuesSent(std::unique_ptr>&& proxyProtocolValuesSent)