]> granicus.if.org Git - pdns/commitdiff
don't confuse dnspcap users with incomplete packets
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 6 Nov 2015 15:04:26 +0000 (16:04 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 6 Nov 2015 15:04:26 +0000 (16:04 +0100)
pdns/dnspcap.cc

index 5ca85d5ce9124cbd61bf325f0eeeee202c1f3a7f..0280d702f7359379ab74d0ed8ea0301909bcfbb7 100644 (file)
@@ -97,6 +97,10 @@ try
       d_udp=reinterpret_cast<const struct udphdr*>(d_buffer + d_skipMediaHeader + 4 * d_ip->ip_hl);
       d_payload = (unsigned char*)d_udp + sizeof(struct udphdr);
       d_len = ntohs(d_udp->uh_ulen) - sizeof(struct udphdr);
+      if((const char*)d_payload + d_len > d_buffer + d_pheader.caplen) {
+       d_runts++;
+       continue;
+      }
       d_correctpackets++;
       return true;
     }
@@ -104,6 +108,11 @@ try
       d_udp=reinterpret_cast<const struct udphdr*>(d_buffer + d_skipMediaHeader + sizeof(struct ip6_hdr));
       d_payload = (unsigned char*)d_udp + sizeof(struct udphdr);
       d_len = ntohs(d_udp->uh_ulen) - sizeof(struct udphdr);
+      if((const char*)d_payload + d_len > d_buffer + d_pheader.caplen) {
+       d_runts++;
+       continue;
+      }
+
       d_correctpackets++;
       return true;
     }