From 82c78710b81e83cc6cc5b19293b7ae8fa1e09bc6 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 6 Jan 2026 15:00:51 +0100 Subject: [PATCH] dnsdist: Prevent surprise exceptions raised in a dtor Reported by Coverity. Signed-off-by: Remi Gacogne --- pdns/dnsdistdist/dnsdist-idstate.cc | 62 ++++++++++++++++------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-idstate.cc b/pdns/dnsdistdist/dnsdist-idstate.cc index 5f5576da0b..8089b30162 100644 --- a/pdns/dnsdistdist/dnsdist-idstate.cc +++ b/pdns/dnsdistdist/dnsdist-idstate.cc @@ -65,42 +65,48 @@ InternalQueryState InternalQueryState::partialCloneForXFR() const InternalQueryState::~InternalQueryState() { #ifndef DISABLE_PROTOBUF - if (delayedResponseMsgs.empty() && ottraceLoggers.empty()) { - return; - } + try { + if (delayedResponseMsgs.empty() && ottraceLoggers.empty()) { + return; + } - std::string OTData; - static thread_local string pbBuf; - pbBuf.clear(); + std::string OTData; + static thread_local string pbBuf; + pbBuf.clear(); - if (tracingEnabled && d_OTTracer != nullptr) { - pdns::ProtoZero::Message msg{pbBuf}; - OTData = d_OTTracer->getOTProtobuf(); - msg.setOpenTelemetryData(OTData); - } + if (tracingEnabled && d_OTTracer != nullptr) { + pdns::ProtoZero::Message msg{pbBuf}; + OTData = d_OTTracer->getOTProtobuf(); + msg.setOpenTelemetryData(OTData); + } - if (!delayedResponseMsgs.empty()) { - for (auto const& msg_logger : delayedResponseMsgs) { - // TODO: we should probably do something with the return value of queueData - if (!tracingEnabled) { - msg_logger.second->queueData(msg_logger.first); - continue; + if (!delayedResponseMsgs.empty()) { + for (auto const& msg_logger : delayedResponseMsgs) { + // TODO: we should probably do something with the return value of queueData + if (!tracingEnabled) { + msg_logger.second->queueData(msg_logger.first); + continue; + } + // Protobuf wireformat allows us to simply append the second "message" + // that only contains the OTTrace data as a single bytes field + msg_logger.second->queueData(msg_logger.first + pbBuf); } - // Protobuf wireformat allows us to simply append the second "message" - // that only contains the OTTrace data as a single bytes field - msg_logger.second->queueData(msg_logger.first + pbBuf); } - } - if (!ottraceLoggers.empty()) { - pbBuf.clear(); - pdns::ProtoZero::Message minimalMsg{pbBuf}; - minimalMsg.setType(pdns::ProtoZero::Message::MessageType::DNSQueryType); - minimalMsg.setOpenTelemetryData(OTData); - for (auto const& msg_logger : ottraceLoggers) { - msg_logger->queueData(pbBuf); + if (!ottraceLoggers.empty()) { + pbBuf.clear(); + pdns::ProtoZero::Message minimalMsg{pbBuf}; + minimalMsg.setType(pdns::ProtoZero::Message::MessageType::DNSQueryType); + minimalMsg.setOpenTelemetryData(OTData); + for (auto const& msg_logger : ottraceLoggers) { + msg_logger->queueData(pbBuf); + } } } + catch (...) { + /* We don't want any uncaught exceptions in a dtor and + in theory the protozero code can throw */ + } #endif } -- 2.47.3