]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Simplify loop to parse address in incoming packet
authorNicko Dehaine <nicko@threatstop.com>
Thu, 2 Jan 2020 18:29:34 +0000 (10:29 -0800)
committerNicko Dehaine <nicko@threatstop.com>
Tue, 18 Aug 2020 23:16:44 +0000 (23:16 +0000)
pdns/dnsrecords.cc

index 6a351f1fd01ae9501bb6288cc3dc7725cc13e1c9..9e7be736fa4fddcc88faa06b53d7ef655e22acc8 100644 (file)
@@ -514,19 +514,17 @@ std::shared_ptr<DNSRecordContent> APLRecordContent::make(const DNSRecord &dr, Pa
       throw MOADNSException("Invalid IP length for IPv4 APL");
     }
     bzero(ret->d_ip4, sizeof(ret->d_ip4));
-    for (int i=0; i < 4; i++) {
-      if (i < ret->d_afdlength)
-        pr.xfr8BitInt(ret->d_ip4[i]);
-    }
+    // Call min because we can't trust d_afdlength in an inbound packet
+    for (u_int i=0; i < min(ret->d_afdlength, (u_int)4); i++)
+      pr.xfr8BitInt(ret->d_ip4[i]);
   } else if (ret->d_family == APL_FAMILY_IPV6) {
     if (ret->d_afdlength > 16) {
       throw MOADNSException("Invalid IP length for IPv6 APL");
     }
     bzero(ret->d_ip6, sizeof(ret->d_ip6));
-    for (int i=0; i< 16; i++) {
-      if (i < ret->d_afdlength)
-        pr.xfr8BitInt(ret->d_ip6[i]);
-    }
+    // Call min because we can't trust d_afdlength in an inbound packet
+    for (u_int i=0; i < min(ret->d_afdlength, (u_int)16); i++)
+      pr.xfr8BitInt(ret->d_ip6[i]);
   } else
     throw MOADNSException("Unknown family for APL record");