]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
API: fix crash when checking if RR is part of parent zone 2687/head
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Wed, 12 Aug 2015 19:09:43 +0000 (21:09 +0200)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Wed, 12 Aug 2015 19:09:43 +0000 (21:09 +0200)
pdns/ws-auth.cc

index 2cd31911d97785e4a3d8389f5d57f1e02e27e8ba..9ad8efebeaa4eb915b76fb66b1402f2f5cfae2df 100644 (file)
@@ -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<DNSResourceRecord> new_records;
   vector<Comment> new_comments;
   vector<DNSResourceRecord> 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) {