From 786aacb73b9dafad2732dcd5930de6128b310b7c Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Tue, 22 Aug 2017 14:10:27 +0200 Subject: [PATCH] Catch DNSName exception in the Zoneparser This wraps all calls to `toCanonic` in try/catch and rethrows it as a PDNSException with more information. Closes #5520. (cherry picked from commit 1293f91eac4810769b88b6cfc404c60b1d5abee0) --- pdns/zoneparser-tng.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pdns/zoneparser-tng.cc b/pdns/zoneparser-tng.cc index 16afed667..b573c7649 100644 --- a/pdns/zoneparser-tng.cc +++ b/pdns/zoneparser-tng.cc @@ -421,8 +421,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; @@ -439,8 +444,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; @@ -451,7 +461,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: @@ -462,8 +476,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(); -- 2.40.0