]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Catch DNSName exception in the Zoneparser 5641/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 22 Aug 2017 12:10:27 +0000 (14:10 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 22 Aug 2017 12:20:15 +0000 (14:20 +0200)
This wraps all calls to `toCanonic` in try/catch and rethrows it as a
PDNSException with more information.

Closes #5520.

pdns/zoneparser-tng.cc

index 153d89239ce33e265195223045215fcf17efbfa2..9906ef40fc14536322d1b3aa8956f9589fd8fa92 100644 (file)
@@ -422,8 +422,13 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
   case QType::MX:
     stringtok(recparts, rr.content);
     if(recparts.size()==2) {
-      if (recparts[1]!=".")
-        recparts[1] = toCanonic(d_zonename, recparts[1]).toStringRootDot();
+      if (recparts[1]!=".") {
+        try {
+          recparts[1] = toCanonic(d_zonename, recparts[1]).toStringRootDot();
+        } catch (std::exception &e) {
+          throw PDNSException("Error in record '" + rr.qname.toString() + " " + rr.qtype.getName() + "': " + e.what());
+        }
+      }
       rr.content=recparts[0]+" "+recparts[1];
     }
     break;
@@ -440,8 +445,13 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
   case QType::SRV:
     stringtok(recparts, rr.content);
     if(recparts.size()==4) {
-      if(recparts[3]!=".")
-        recparts[3] = toCanonic(d_zonename, recparts[3]).toStringRootDot();
+      if(recparts[3]!=".") {
+        try {
+          recparts[3] = toCanonic(d_zonename, recparts[3]).toStringRootDot();
+        } catch (std::exception &e) {
+          throw PDNSException("Error in record '" + rr.qname.toString() + " " + rr.qtype.getName() + "': " + e.what());
+        }
+      }
       rr.content=recparts[0]+" "+recparts[1]+" "+recparts[2]+" "+recparts[3];
     }
     break;
@@ -452,7 +462,11 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
   case QType::DNAME:
   case QType::PTR:
   case QType::AFSDB:
-    rr.content=toCanonic(d_zonename, rr.content).toStringRootDot();
+    try {
+      rr.content = toCanonic(d_zonename, rr.content).toStringRootDot();
+    } catch (std::exception &e) {
+      throw PDNSException("Error in record '" + rr.qname.toString() + " " + rr.qtype.getName() + "': " + e.what());
+    }
     break;
 
   case QType::SOA:
@@ -463,8 +477,8 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
       try {
         recparts[0]=toCanonic(d_zonename, recparts[0]).toStringRootDot();
         recparts[1]=toCanonic(d_zonename, recparts[1]).toStringRootDot();
-      } catch (runtime_error &re) {
-        throw PDNSException(re.what());
+      } catch (std::exception &e) {
+        throw PDNSException("Error in record '" + rr.qname.toString() + " " + rr.qtype.getName() + "': " + e.what());
       }
     }
     rr.content.clear();