From: Nicko Dehaine Date: Thu, 2 Jan 2020 18:29:34 +0000 (-0800) Subject: Simplify loop to parse address in incoming packet X-Git-Tag: rec-4.4.0-beta1~4^2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=688724814ac4a9b47c270ee5a45cfceaddf8e3ee;p=thirdparty%2Fpdns.git Simplify loop to parse address in incoming packet --- diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 6a351f1fd0..9e7be736fa 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -514,19 +514,17 @@ std::shared_ptr 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");