From d605f9b1321ab9ee3f088cc9f9e54b7d08c89879 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 27 Aug 2018 23:35:49 +0200 Subject: [PATCH] ixfrdist: Fix invalid buffer usage in getSerialFromMaster() --- pdns/ixfrutils.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pdns/ixfrutils.cc b/pdns/ixfrutils.cc index 180b494291..04c832451d 100644 --- a/pdns/ixfrutils.cc +++ b/pdns/ixfrutils.cc @@ -49,10 +49,14 @@ uint32_t getSerialFromMaster(const ComboAddress& master, const DNSName& zone, sh s.writen(msg); string reply; - char buf[4096]; + reply.resize(4096); // will throw a NetworkError on timeout - s.readWithTimeout(buf, sizeof(buf), timeout); - reply.assign(buf); + ssize_t got = s.readWithTimeout(&reply[0], reply.size(), timeout); + if (got < 0 || static_cast(got) < sizeof(dnsheader)) { + throw std::runtime_error("Invalid response size " + std::to_string(got)); + } + + reply.resize(got); MOADNSParser mdp(false, reply); if(mdp.d_header.rcode) { -- 2.47.2