]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Simplify !a.isPartOf(b) && a != b constructs. 15441/head
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 23 Apr 2025 12:20:52 +0000 (14:20 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 23 Apr 2025 14:46:21 +0000 (16:46 +0200)
By design, a.isPartOf(a) is always true.
Therefore, if a and b compare equal, !a.isPartOf(b) and a != b are both
false and the result of the expression is false, but also
!a.isPartOf(b).

If not, then a != b is true and the result of the expression is
!a.isPartOf(b).

Boolean algebra is hard, let's go shopping.

pdns/pdnsutil.cc
pdns/ws-auth.cc
pdns/zonemd.cc

index 65d3a2f96524ba70ee99d24c2fe8783bec7b2cbb..7559a3b75d5842a7939e635c030e05773cbdeddb 100644 (file)
@@ -1574,7 +1574,7 @@ static int loadZone(const ZoneName& zone, const string& fname) {
   rr.domain_id=di.id;
   bool haveSOA = false;
   while(zpt.get(rr)) {
-    if(!rr.qname.isPartOf(zone) && rr.qname!=zone.operator const DNSName&()) {
+    if(!rr.qname.isPartOf(zone)) {
       cerr<<"File contains record named '"<<rr.qname<<"' which is not part of zone '"<<zone<<"'"<<endl;
       return EXIT_FAILURE;
     }
index a43323b408470038d8aec1b76f84ae9bad0442f5..fc3d54b22c5c60fa065b546d0b2a4bcfc6844606 100644 (file)
@@ -1915,7 +1915,7 @@ static void apiServerZonesPOST(HttpRequest* req, HttpResponse* resp)
 
   for (auto& resourceRecord : new_records) {
     resourceRecord.qname.makeUsLowerCase();
-    if (!resourceRecord.qname.isPartOf(zonename) && resourceRecord.qname != zonename.operator const DNSName&()) {
+    if (!resourceRecord.qname.isPartOf(zonename)) {
       throw ApiException("RRset " + resourceRecord.qname.toString() + " IN " + resourceRecord.qtype.toString() + ": Name is out of zone");
     }
 
@@ -2123,7 +2123,7 @@ static void apiServerZoneDetailPUT(HttpRequest* req, HttpResponse* resp)
 
     for (auto& resourceRecord : new_records) {
       resourceRecord.qname.makeUsLowerCase();
-      if (!resourceRecord.qname.isPartOf(zoneData.zoneName) && resourceRecord.qname != zoneData.zoneName.operator const DNSName&()) {
+      if (!resourceRecord.qname.isPartOf(zoneData.zoneName)) {
         throw ApiException("RRset " + resourceRecord.qname.toString() + " IN " + resourceRecord.qtype.toString() + ": Name is out of zone");
       }
       apiCheckQNameAllowedCharacters(resourceRecord.qname.toString());
@@ -2335,7 +2335,7 @@ static void patchZone(UeberBackend& backend, const ZoneName& zonename, DomainInf
       }
       else if (changetype == "REPLACE") {
         // we only validate for REPLACE, as DELETE can be used to "fix" out of zone records.
-        if (!qname.isPartOf(zonename) && qname != zonename.operator const DNSName&()) {
+        if (!qname.isPartOf(zonename)) {
           throw ApiException("RRset " + qname.toString() + " IN " + qtype.toString() + ": Name is out of zone");
         }
 
index bed599382b0e0c0983317ad7ca8741e5c9172e0b..99a386e3d4748246ea6e16bf076713da972208fd 100644 (file)
@@ -123,7 +123,7 @@ void pdns::ZoneMD::processRecord(const DNSRecord& record)
 
 void pdns::ZoneMD::readRecord(const DNSRecord& record)
 {
-  if (!record.d_name.isPartOf(d_zone) && record.d_name != DNSName(d_zone)) {
+  if (!record.d_name.isPartOf(d_zone)) {
     return;
   }
   if (record.d_class == QClass::IN && record.d_type == QType::SOA && d_soaRecordContent) {