]> granicus.if.org Git - pdns/commitdiff
dnsdist: Catch exceptions thrown when handling a TCP response
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 Jul 2019 08:28:01 +0000 (10:28 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 Jul 2019 08:28:01 +0000 (10:28 +0200)
We need to handle it gracefully if a function called from
handleResponse() throws, most likely because the answer received
from the backend was not valid.

pdns/dnsdist-tcp.cc

index be50cd305bb86480a0dfa5a0b2e95e2d3422d321..e49897902b82b0d9caa25432c6ad734767473854 100644 (file)
@@ -968,7 +968,12 @@ static void handleDownstreamIO(std::shared_ptr<IncomingTCPConnectionState>& stat
         fd = -1;
 
         state->d_responseReadTime = now;
-        handleResponse(state, now);
+        try {
+          handleResponse(state, now);
+        }
+        catch (const std::exception& e) {
+          vinfolog("Got an exception while handling TCP response from %s (client is %s): %s", state->d_ds ? state->d_ds->getName() : "unknown", state->d_ci.remote.toStringWithPort(), e.what());
+        }
         return;
       }
     }
@@ -993,7 +998,7 @@ static void handleDownstreamIO(std::shared_ptr<IncomingTCPConnectionState>& stat
     }
 
     /* don't increase this counter when reusing connections */
-    if (state->d_downstreamConnection->isFresh()) {
+    if (state->d_downstreamConnection && state->d_downstreamConnection->isFresh()) {
       ++state->d_downstreamFailures;
     }
     if (state->d_outstanding && state->d_ds != nullptr) {