From edda67a2319218478029950765e8930ef69c2559 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Wed, 12 Aug 2015 21:09:43 +0200 Subject: [PATCH] API: fix crash when checking if RR is part of parent zone --- pdns/ws-auth.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 2cd31911d..9ad8efebe 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -608,7 +608,6 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) { zonename.resize(zonename.size()-1); } - string dotsuffix = "." + zonename; string zonestring = stringFromJson(document, "zone", ""); bool exists = B.getDomainInfo(zonename, di); @@ -654,7 +653,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) { DNSResourceRecord rr; BOOST_FOREACH(rr, new_records) { - if (!rr.qname.isPartOf(dotsuffix) && !pdns_iequals(rr.qname, zonename)) + if (!rr.qname.isPartOf(zonename) && !pdns_iequals(rr.qname, zonename)) throw ApiException("RRset "+rr.qname.toString()+" IN "+rr.qtype.getName()+": Name is out of zone"); if (rr.qtype.getCode() == QType::SOA && pdns_iequals(rr.qname, zonename)) { @@ -940,7 +939,6 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) { if (!B.getDomainInfo(zonename, di)) throw ApiException("Could not find domain '"+zonename+"'"); - string dotsuffix = "." + zonename; vector new_records; vector new_comments; vector new_ptrs; @@ -963,9 +961,9 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) { for(SizeType rrsetIdx = 0; rrsetIdx < rrsets.Size(); ++rrsetIdx) { const Value& rrset = rrsets[rrsetIdx]; - string qname, changetype; + string changetype; QType qtype; - qname = stringFromJson(rrset, "name"); + DNSName qname = stringFromJson(rrset, "name"); qtype = stringFromJson(rrset, "type"); changetype = toUpper(stringFromJson(rrset, "changetype")); @@ -977,8 +975,8 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) { } else if (changetype == "REPLACE") { // we only validate for REPLACE, as DELETE can be used to "fix" out of zone records. - if (!iends_with(qname, dotsuffix) && !pdns_iequals(qname, zonename)) - throw ApiException("RRset "+qname+" IN "+qtype.getName()+": Name is out of zone"); + if (!qname.isPartOf(zonename) && !pdns_iequals(qname, zonename)) + throw ApiException("RRset "+qname.toString()+" IN "+qtype.getName()+": Name is out of zone"); new_records.clear(); new_comments.clear(); @@ -990,7 +988,7 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) { rr.domain_id = di.id; if (rr.qname != qname || rr.qtype != qtype) - throw ApiException("Record "+rr.qname.toString()+"/"+rr.qtype.getName()+" "+rr.content+": Record wrongly bundled with RRset " + qname + "/" + qtype.getName()); + throw ApiException("Record "+rr.qname.toString()+"/"+rr.qtype.getName()+" "+rr.content+": Record wrongly bundled with RRset " + qname.toString() + "/" + qtype.getName()); if (rr.qtype.getCode() == QType::SOA && pdns_iequals(rr.qname, zonename)) { soa_edit_done = increaseSOARecord(rr, soa_edit_api_kind, soa_edit_kind); @@ -1005,7 +1003,7 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) { bool replace_comments = rrset["comments"].IsArray(); if (!replace_records && !replace_comments) { - throw ApiException("No change for RRset " + qname + "/" + qtype.getName()); + throw ApiException("No change for RRset " + qname.toString() + "/" + qtype.getName()); } if (replace_records) { -- 2.40.0