]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: backport of 9268 to 4.3.x: Better exception handling in houseKeeping / handlePol...
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 7 Jul 2020 08:54:15 +0000 (10:54 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 7 Jul 2020 08:54:15 +0000 (10:54 +0200)
pdns/pdns_recursor.cc

index eb95325613ff1bc5606edb3e4ac67f1acb643d40..1ad3b241e19ba070fb0371fe3ecfdff347b8b37f 100644 (file)
@@ -1359,7 +1359,23 @@ static void startDoResolve(void *p)
             spoofed=appliedPolicy.getCustomRecords(dc->d_mdp.d_qname, dc->d_mdp.d_qtype);
             for (const 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 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 while resolving '"<<dc->d_mdp.d_qname<<"' because another RPZ policy was hit"<<endl;
+                }
+                res = RCode::ServFail;
+                break;
+              }
             }
             goto haveAnswer;
           case DNSFilterEngine::PolicyKind::Truncate:
@@ -2946,7 +2962,24 @@ static void houseKeeping(void *)
       int res = SyncRes::getRootNS(g_now, nullptr);
       if (!res) {
         last_rootupdate=now.tv_sec;
-        primeRootNSZones(g_dnssecmode != DNSSECMode::Off);
+        try {
+          primeRootNSZones(g_dnssecmode != DNSSECMode::Off);
+        }
+        catch (const std::exception& e) {
+          g_log<<Logger::Error<<"Exception while priming the root NS zones: "<<e.what()<<endl;
+        }
+        catch (const PDNSException& e) {
+          g_log<<Logger::Error<<"Exception while priming the root NS zones: "<<e.reason<<endl;
+        }
+        catch (const ImmediateServFailException& e) {
+          g_log<<Logger::Error<<"Exception while priming the root NS zones: "<<e.reason<<endl;
+        }
+        catch (const PolicyHitException& e) {
+          g_log<<Logger::Error<<"Policy hit while priming the root NS zones"<<endl;
+        }
+        catch (...) {
+          g_log<<Logger::Error<<"Exception while priming the root NS zones"<<endl;
+        }
       }
     }
 
@@ -3001,6 +3034,12 @@ static void houseKeeping(void *)
       g_log<<Logger::Error<<"Fatal error in housekeeping thread: "<<ae.reason<<endl;
       throw;
     }
+  catch(...)
+    {
+      s_running=false;
+      g_log<<Logger::Error<<"Uncaught exception in housekeeping thread"<<endl;
+      throw;
+    }
 }
 
 static void makeThreadPipes()