From bf06a3d6b2f517b0cf365e218c752548029ea4a6 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 --- 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 2e00169e3..d8e3b0260 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -1909,6 +1909,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) { @@ -1919,8 +1921,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