]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
tcpiohandler: Don't throw exceptions over the C/C++ boundary
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 18 May 2026 10:37:30 +0000 (12:37 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 18 May 2026 10:37:30 +0000 (12:37 +0200)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/tcpiohandler.cc

index 7ee5cfbaa05a410c19532a46ded828d865d7cf0a..176b20c64b486ecc65aca46dd4c6bd8a691589f9 100644 (file)
@@ -936,7 +936,13 @@ public:
       return 0;
     }
 
-    conn->addNewTicket(session);
+    try {
+      conn->addNewTicket(session);
+    }
+    // NOLINTNEXTLINE(bugprone-empty-catch)
+    catch (...) {
+    }
+
     return 1;
   }
 
@@ -1299,7 +1305,7 @@ public:
       return 0;
     }
 
-    GnuTLSConnection* conn = reinterpret_cast<GnuTLSConnection*>(gnutls_session_get_ptr(session));
+    auto* conn = reinterpret_cast<GnuTLSConnection*>(gnutls_session_get_ptr(session));
     if (conn == nullptr) {
       return 0;
     }
@@ -1308,7 +1314,10 @@ public:
     auto ret = gnutls_session_get_data2(session, &sess);
     /* GnuTLS returns a 'fake' ticket of 4 bytes set to zero when there is no ticket available */
     if (ret != GNUTLS_E_SUCCESS || sess.size <= 4) {
-      throw std::runtime_error("Error getting GnuTLSSession: " + std::string(gnutls_strerror(ret)));
+      if (sess.data != nullptr) {
+        gnutls_free(sess.data);
+      }
+      return 0;
     }
     conn->d_tlsSessions.push_back(std::make_unique<GnuTLSSession>(sess));
     return 0;