From: Charles-Henri Bruyand Date: Wed, 22 Jun 2022 12:27:01 +0000 (+0200) Subject: Make sure that we do not read past our buffer in any case X-Git-Tag: auth-4.8.0-alpha0~43^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=576744f44f8e471861743cb6f3dc985b8763f697;p=thirdparty%2Fpdns.git Make sure that we do not read past our buffer in any case Co-authored-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 1d206b3047..1ec3a2c7e9 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -620,9 +620,11 @@ static void processDOHQuery(DOHUnitUniquePtr&& du) if (du->response.empty()) { du->response = std::move(du->query); } - auto dh = const_cast(reinterpret_cast(du->response.data())); + if (du->response.size() >= sizeof(dnsheader) && du->contentType.empty()) { + auto dh = reinterpret_cast(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; }