From: Pieter Lexis Date: Tue, 22 Aug 2017 12:10:27 +0000 (+0200) Subject: Catch DNSName exception in the Zoneparser X-Git-Tag: auth-4.1.0-rc1~12^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F5641%2Fhead;p=thirdparty%2Fpdns.git 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. --- diff --git a/pdns/zoneparser-tng.cc b/pdns/zoneparser-tng.cc index 153d89239c..9906ef40fc 100644 --- a/pdns/zoneparser-tng.cc +++ b/pdns/zoneparser-tng.cc @@ -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();