From ba78a38a7a2349ec73fa2a66b552eb2234b42007 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 10 Oct 2025 16:40:25 +0200 Subject: [PATCH] dnsdist: Don't choke on invalid DNS payload when generating protobuf messages Signed-off-by: Remi Gacogne --- pdns/dnsdistdist/dnsdist-protobuf.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-protobuf.cc b/pdns/dnsdistdist/dnsdist-protobuf.cc index 633e335a0f..e02b6d8755 100644 --- a/pdns/dnsdistdist/dnsdist-protobuf.cc +++ b/pdns/dnsdistdist/dnsdist-protobuf.cc @@ -195,8 +195,13 @@ void DNSDistProtoBufMessage::serialize(std::string& data) const if (d_dr != nullptr) { msg.setResponseCode(d_rcode ? *d_rcode : d_dr->getHeader()->rcode); - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - msg.addRRsFromPacket(reinterpret_cast(d_dr->getData().data()), d_dr->getData().size(), d_includeCNAME); + try { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + msg.addRRsFromPacket(reinterpret_cast(d_dr->getData().data()), d_dr->getData().size(), d_includeCNAME); + } + catch (const std::exception& exp) { + vinfolog("Error while parsing the RRs from a response packet to add them to the protobuf message: %s", exp.what()); + } } else { if (d_rcode) { -- 2.47.3