From 96de55fb12126449fe726f9fc55679a3edde3c19 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 1 Sep 2025 14:00:09 +0200 Subject: [PATCH] dnsdist: Properly handle truncation for UDP responses sent via `sendmmsg` Signed-off-by: Remi Gacogne (cherry picked from commit bf06a3d6b2f517b0cf365e218c752548029ea4a6) --- pdns/dnsdistdist/dnsdist.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); -- 2.47.3