From: Remi Gacogne Date: Mon, 1 Sep 2025 12:00:09 +0000 (+0200) Subject: dnsdist: Properly handle truncation for UDP responses sent via `sendmmsg` X-Git-Tag: dnsdist-2.0.1~5^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F16081%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Properly handle truncation for UDP responses sent via `sendmmsg` Signed-off-by: Remi Gacogne (cherry picked from commit bf06a3d6b2f517b0cf365e218c752548029ea4a6) --- diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 0977b45ca..6c0cc94be 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -1898,6 +1898,8 @@ static void processUDPQuery(ClientState& clientState, const struct msghdr* msgh, // the buffer might have been invalidated by now (resized) const auto dnsHeader = dnsQuestion.getHeader(); if (result == ProcessQueryResult::SendAnswer) { + /* ensure payload size is not exceeded */ + handleResponseTC4UDPClient(dnsQuestion, udpPayloadSize, query); #ifndef DISABLE_RECVMMSG #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) if (dnsQuestion.ids.delayMsec == 0 && responsesVect != nullptr) { @@ -1908,8 +1910,6 @@ static void processUDPQuery(ClientState& clientState, const struct msghdr* msgh, } #endif /* defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) */ #endif /* DISABLE_RECVMMSG */ - /* ensure payload size is not exceeded */ - handleResponseTC4UDPClient(dnsQuestion, udpPayloadSize, query); /* we use dest, always, because we don't want to use the listening address to send a response since it could be 0.0.0.0 */ sendUDPResponse(clientState.udpFD, query, dnsQuestion.ids.delayMsec, dest, remote);