]> granicus.if.org Git - pdns/commitdiff
auth: Catch exception when parsing a zone's SOA in getUnfreshSlaveInfos()
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 18 Feb 2019 15:16:04 +0000 (16:16 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 18 Feb 2019 15:16:04 +0000 (16:16 +0100)
pdns/backends/gsql/gsqlbackend.cc

index f010a1728b1371041b9d3ee48ed2bba18856256b..be803b88f19d7ffcf31985b3ae615e7b47ee57f5 100644 (file)
@@ -338,36 +338,46 @@ void GSQLBackend::getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains)
   }
 
   vector<DomainInfo> allSlaves;
-  int numanswers=d_result.size();
-  for(int n=0;n<numanswers;++n) { // id,name,master,last_check
+
+  for(const auto& row : d_result) { // id,name,master,last_check
     DomainInfo sd;
-    ASSERT_ROW_COLUMNS("info-all-slaves-query", d_result[n], 4);
-    sd.id=pdns_stou(d_result[n][0]);
+    ASSERT_ROW_COLUMNS("info-all-slaves-query", row, 4);
     try {
-      sd.zone= DNSName(d_result[n][1]);
+      sd.id=pdns_stou(row[0]);
+      sd.zone= DNSName(row[1]);
+
+      vector<string> masters;
+      stringtok(masters, row[2], ", \t");
+      for(const auto& m : masters)
+        sd.masters.emplace_back(m, 53);
+
+      sd.last_check=pdns_stou(row[3]);
+      sd.backend=this;
+      sd.kind=DomainInfo::Slave;
+      allSlaves.push_back(sd);
     } catch (...) {
       continue;
     }
-
-    vector<string> masters;
-    stringtok(masters, d_result[n][2], ", \t");
-    for(const auto& m : masters)
-      sd.masters.emplace_back(m, 53);
-
-    sd.last_check=pdns_stou(d_result[n][3]);
-    sd.backend=this;
-    sd.kind=DomainInfo::Slave;
-    allSlaves.push_back(sd);
   }
 
-  for(vector<DomainInfo>::iterator i=allSlaves.begin();i!=allSlaves.end();++i) {
-    SOAData sdata;
-    sdata.serial=0;
-    sdata.refresh=0;
-    getSOA(i->zone,sdata);
-    if((time_t)(i->last_check+sdata.refresh) < time(0)) {
-      i->serial=sdata.serial;
-      unfreshDomains->push_back(*i);
+  for (auto& slave : allSlaves) {
+    try {
+      SOAData sdata;
+      sdata.serial=0;
+      sdata.refresh=0;
+      getSOA(slave.zone, sdata);
+      if(static_cast<time_t>(slave.last_check + sdata.refresh) < time(nullptr)) {
+        slave.serial=sdata.serial;
+        unfreshDomains->push_back(slave);
+      }
+    }
+    catch(const std::exception& exp) {
+      g_log<<Logger::Warning<<"Error while parsing SOA data for slave zone '"<<slave.zone.toLogString()<<"': "<<exp.what()<<endl;
+      continue;
+    }
+    catch(...) {
+      g_log<<Logger::Warning<<"Error while parsing SOA data for slave zone '"<<slave.zone.toLogString()<<"', skipping"<<endl;
+      continue;
     }
   }
 }