From 3330ec7952ac061121b7f29d9e94c16a4973cdd7 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 13 Mar 2020 16:09:51 +0100 Subject: [PATCH] auth: Ensure qtype is set before calling setContent() in axfrfilter() Otherwise we might fail to strip a trailing dot for some records. --- pdns/lua-auth4.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/pdns/lua-auth4.cc b/pdns/lua-auth4.cc index ede5d1b038..90c527626f 100644 --- a/pdns/lua-auth4.cc +++ b/pdns/lua-auth4.cc @@ -117,21 +117,27 @@ bool AuthLua4::axfrfilter(const ComboAddress& remote, const DNSName& zone, const const auto& rows = std::get<1>(ret); - for(const auto& row: rows) { - DNSResourceRecord rec; - for(const auto& col: row.second) { - if (col.first == "qtype") - rec.qtype = QType(boost::get(col.second)); - else if (col.first == "qname") - rec.qname = DNSName(boost::get(col.second)).makeLowerCase(); - else if (col.first == "ttl") - rec.ttl = boost::get(col.second); - else if (col.first == "content") - rec.setContent(boost::get(col.second)); - else - throw PDNSException("Cannot understand "+col.first+" in axfr filter response on row "+std::to_string(row.first)); + try { + for(const auto& row: rows) { + DNSResourceRecord rec; + + const auto& map = row.second; + rec.qtype = QType(boost::get(map.at("qtype"))); + rec.qname = DNSName(boost::get(map.at("qname"))); + rec.qname.makeUsLowerCase(); + if (map.count("ttl")) { + rec.ttl = boost::get(map.at("ttl")); + } + rec.setContent(boost::get(map.at("content"))); + + out.push_back(rec); } - out.push_back(rec); + } + catch (const std::exception& e) { + throw PDNSException("Cannot understand axfr filter response: " + std::string(e.what())); + } + catch (const PDNSException& e) { + throw PDNSException("Cannot understand axfr filter response: " + e.reason); } return true; -- 2.47.2