]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Better exception handling in handlePolicyHit() 9268/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Jun 2020 13:09:13 +0000 (15:09 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Jun 2020 13:15:55 +0000 (15:15 +0200)
An ImmediateServFailException being raised during the call to
SyncRes::beginResolve() from handleRPZCustom() could lead to
the resolution process to stop without any response being sent:

Any other exception in a resolver context (www.example.net/A from 127.0.0.1:4242)

This commit turns into a ServFail answer instead.

pdns/pdns_recursor.cc

index a13434dcfc9005bb9dbd0df40875f7455a57db15..a644bc57ef490ee89947a0e88278ff3c8a3c5218 100644 (file)
@@ -1237,7 +1237,23 @@ static PolicyResult handlePolicyHit(const DNSFilterEngine::Policy& appliedPolicy
       auto spoofed = appliedPolicy.getCustomRecords(dc->d_mdp.d_qname, dc->d_mdp.d_qtype);
       for (auto& dr : spoofed) {
         ret.push_back(dr);
-        handleRPZCustom(dr, QType(dc->d_mdp.d_qtype), sr, res, ret);
+        try {
+          handleRPZCustom(dr, QType(dc->d_mdp.d_qtype), sr, res, ret);
+        }
+        catch (const ImmediateServFailException& e) {
+          if (g_logCommonErrors) {
+            g_log << Logger::Notice << "Sending SERVFAIL to " << dc->getRemote() << " during resolve of the custom filter policy '" << appliedPolicy.getName() << "' while resolving '"<<dc->d_mdp.d_qname<<"' because: "<<e.reason<<endl;
+          }
+          res = RCode::ServFail;
+          break;
+        }
+        catch (const PolicyHitException& e) {
+          if (g_logCommonErrors) {
+            g_log << Logger::Notice << "Sending SERVFAIL to " << dc->getRemote() << " during resolve of the custom filter policy '" << appliedPolicy.getName() << "' while resolving '"<<dc->d_mdp.d_qname<<"' because another RPZ policy was hit"<<endl;
+          }
+          res = RCode::ServFail;
+          break;
+        }
       }
     }
     return PolicyResult::HaveAnswer;