]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make sure that we do not read past our buffer in any case 11712/head
authorCharles-Henri Bruyand <charleshenri.bruyand+github@gmail.com>
Wed, 22 Jun 2022 12:27:01 +0000 (14:27 +0200)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Wed, 22 Jun 2022 14:04:25 +0000 (16:04 +0200)
Co-authored-by: Remi Gacogne <github@coredump.fr>
pdns/dnsdistdist/doh.cc

index 1d206b30478a0cdc3d8ccac830853d5a213d482a..1ec3a2c7e9f043fa8ecdf0b3d762750f9ca3c9ad 100644 (file)
@@ -620,9 +620,11 @@ static void processDOHQuery(DOHUnitUniquePtr&& du)
       if (du->response.empty()) {
         du->response = std::move(du->query);
       }
-      auto dh = const_cast<struct dnsheader*>(reinterpret_cast<const struct dnsheader*>(du->response.data()));
+      if (du->response.size() >= sizeof(dnsheader) && du->contentType.empty()) {
+        auto dh = reinterpret_cast<const struct dnsheader*>(du->response.data());
 
-      handleResponseSent(qname, QType(qtype), 0., du->ids.origDest, ComboAddress(), du->response.size(), *dh, dnsdist::Protocol::DoH);
+        handleResponseSent(qname, QType(qtype), 0., du->ids.origDest, ComboAddress(), du->response.size(), *dh, dnsdist::Protocol::DoH);
+      }
       sendDoHUnitToTheMainThread(std::move(du), "DoH self-answered response");
       return;
     }