]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Prevent surprise exceptions raised in a dtor 16700/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 6 Jan 2026 14:00:51 +0000 (15:00 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 6 Jan 2026 14:00:51 +0000 (15:00 +0100)
Reported by Coverity.

Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-idstate.cc

index 5f5576da0b1595011410fdc51bb534a127e3b46b..8089b30162102b5be554b66ac5c1d0d894e94219 100644 (file)
@@ -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
 }