]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix an out-of-bounds read (up to 4 bytes) in the packet cache
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 2 Apr 2020 14:49:44 +0000 (16:49 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 1 Sep 2020 08:50:06 +0000 (10:50 +0200)
Detected by OSS-Fuzz. Also make sure that we don't try to parse
packets smaller than 12 bytes in the fuzzing target, those are
usually dropped earlier.

pdns/fuzz_packetcache.cc
pdns/packetcache.hh

index c53306c744ab795cfc37e3e6d459e585c706ad11..98f99d372fbf4e67fab7b001683224936841305e 100644 (file)
@@ -29,7 +29,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
 
-  if (size > std::numeric_limits<uint16_t>::max()) {
+  if (size > std::numeric_limits<uint16_t>::max() || size < sizeof(dnsheader)) {
     return 0;
   }
 
index 9baa8b3dd6345526fb91b3e82a4335bd872178b1..bbb670df579a120793c1390c705ee7c9ef2fb6b5 100644 (file)
@@ -76,7 +76,7 @@ public:
     uint16_t optionLen;
 
     while (pos < packetSize && rdataRead < rdLen && getNextEDNSOption(&packet.at(pos), rdLen - rdataRead, optionCode, optionLen)) {
-      if (optionLen > (rdLen - rdataRead)) {
+      if (optionLen > (rdLen - rdataRead - 4)) {
         if (packetSize > pos) {
           currentHash = burtle(reinterpret_cast<const unsigned char*>(&packet.at(pos)), packetSize - pos, currentHash);
         }