From: Remi Gacogne Date: Tue, 6 Jan 2026 14:00:51 +0000 (+0100) Subject: dnsdist: Prevent surprise exceptions raised in a dtor X-Git-Tag: rec-5.4.0-beta1~55^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16700%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Prevent surprise exceptions raised in a dtor Reported by Coverity. Signed-off-by: Remi Gacogne --- 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 }