From: Remi Gacogne Date: Fri, 9 Nov 2018 10:18:35 +0000 (+0100) Subject: rec: Refuse queries for all meta-types X-Git-Tag: auth-4.2.0-alpha1~56^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25e654f7f9725c474d96c7eca57cb34fe41c4669;p=pdns rec: Refuse queries for all meta-types --- diff --git a/pdns/recursordist/test-syncres_cc.cc b/pdns/recursordist/test-syncres_cc.cc index c6c8782b8..48cf7abd4 100644 --- a/pdns/recursordist/test-syncres_cc.cc +++ b/pdns/recursordist/test-syncres_cc.cc @@ -665,6 +665,31 @@ BOOST_AUTO_TEST_CASE(test_edns_formerr_but_edns_enabled) { } } +BOOST_AUTO_TEST_CASE(test_meta_types) { + std::unique_ptr sr; + initSR(sr); + + static const std::set invalidTypes = { 128, QType::AXFR, QType::IXFR, QType::RRSIG, QType::NSEC3, QType::OPT, QType::TSIG, QType::TKEY, QType::MAILA, QType::MAILB, 65535 }; + + for (const auto qtype : invalidTypes) { + size_t queriesCount = 0; + + sr->setAsyncCallback([&queriesCount](const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional& srcmask, boost::optional context, LWResult* res, bool* chained) { + + queriesCount++; + return 0; + }); + + primeHints(); + + vector ret; + int res = sr->beginResolve(DNSName("powerdns.com."), QType(qtype), QClass::IN, ret); + BOOST_CHECK_EQUAL(res, -1); + BOOST_CHECK_EQUAL(ret.size(), 0); + BOOST_CHECK_EQUAL(queriesCount, 0); + } +} + BOOST_AUTO_TEST_CASE(test_tc_fallback_to_tcp) { std::unique_ptr sr; initSR(sr); diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 84ae05c70..6c9fcbccf 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -119,8 +119,6 @@ SyncRes::SyncRes(const struct timeval& now) : d_authzonequeries(0), d_outquerie /** everything begins here - this is the entry point just after receiving a packet */ int SyncRes::beginResolve(const DNSName &qname, const QType &qtype, uint16_t qclass, vector&ret) { - /* rfc6895 section 3.1 + RRSIG and NSEC3 */ - static const std::set metaTypes = { QType::AXFR, QType::IXFR, QType::RRSIG, QType::NSEC3, QType::OPT, QType::TSIG, QType::TKEY, QType::MAILA, QType::MAILB }; vState state = Indeterminate; s_queries++; d_wasVariable=false; @@ -131,7 +129,9 @@ int SyncRes::beginResolve(const DNSName &qname, const QType &qtype, uint16_t qcl return 0; // so do check before updating counters (we do now) } - if (metaTypes.count(qtype.getCode())) { + auto qtypeCode = qtype.getCode(); + /* rfc6895 section 3.1 */ + if ((qtypeCode >= 128 && qtypeCode <= 254) || qtypeCode == QType::RRSIG || qtypeCode == QType::NSEC3 || qtypeCode == QType::OPT || qtypeCode == 65535) { return -1; }