From: Remi Gacogne Date: Mon, 24 Jul 2017 11:08:31 +0000 (+0200) Subject: rec: Prevent an infinite loop if we need auth and the best match is not X-Git-Tag: dnsdist-1.2.0~47^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8d4f4984962c3fb8efbdfd959c5b893fe029a7d;p=pdns rec: Prevent an infinite loop if we need auth and the best match is not --- diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index 475e7a1a7..38f48121f 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -105,6 +105,8 @@ MemRecursorCache::cache_t::const_iterator MemRecursorCache::getEntryUsingECSInde if (!requireAuth || entry->d_auth) { return entry; } + /* we need auth data and the best match is not authoritative */ + return d_cache.end(); } else { /* this netmask-specific entry has expired */ diff --git a/pdns/recursordist/test-recursorcache_cc.cc b/pdns/recursordist/test-recursorcache_cc.cc index 162df7610..6269a8556 100644 --- a/pdns/recursordist/test-recursorcache_cc.cc +++ b/pdns/recursordist/test-recursorcache_cc.cc @@ -253,11 +253,14 @@ BOOST_AUTO_TEST_CASE(test_RecursorCacheSimple) { records.push_back(dr2); MRC.replace(now, power, QType(QType::A), records, signatures, authRecords, false, boost::none); BOOST_CHECK_EQUAL(MRC.size(), 1); + // let's first check that non-auth is not returned when we need authoritative data + BOOST_CHECK_EQUAL(MRC.get(now, power, QType(QType::A), true, &retrieved, ComboAddress("127.0.0.1"), nullptr), -now); BOOST_CHECK_EQUAL(MRC.get(now, power, QType(QType::A), false, &retrieved, ComboAddress("127.0.0.1"), nullptr), (ttd-now)); BOOST_REQUIRE_EQUAL(retrieved.size(), 1); BOOST_CHECK_EQUAL(getRR(retrieved.at(0))->getCA().toString(), dr2Content.toString()); - // Most specific netmask test + /**** Most specific netmask tests ****/ + // wipe everything MRC.doWipeCache(DNSName("."), true); BOOST_CHECK_EQUAL(MRC.size(), 0); @@ -298,6 +301,28 @@ BOOST_AUTO_TEST_CASE(test_RecursorCacheSimple) { BOOST_REQUIRE_EQUAL(retrieved.size(), 1); BOOST_CHECK_EQUAL(getRR(retrieved.at(0))->getCA().toString(), dr4Content.toString()); retrieved.clear(); + + // wipe everything + MRC.doWipeCache(DNSName("."), true); + BOOST_CHECK_EQUAL(MRC.size(), 0); + records.clear(); + + // insert an entry for 192.0.0.1/8, non auth + records.clear(); + records.push_back(dr2); + MRC.replace(now, power, QType(QType::A), records, signatures, authRecords, false, boost::optional("192.0.0.1/8")); + BOOST_CHECK_EQUAL(MRC.size(), 1); + + // we should not get it when we need authoritative data + BOOST_CHECK_EQUAL(MRC.get(now, power, QType(QType::A), true, &retrieved, ComboAddress("192.168.0.1"), nullptr), -1); + BOOST_REQUIRE_EQUAL(retrieved.size(), 0); + retrieved.clear(); + + // but we should when we are OK with non-auth + BOOST_CHECK_EQUAL(MRC.get(now, power, QType(QType::A), false, &retrieved, ComboAddress("192.168.0.1"), nullptr), (ttd-now)); + BOOST_REQUIRE_EQUAL(retrieved.size(), 1); + BOOST_CHECK_EQUAL(getRR(retrieved.at(0))->getCA().toString(), dr2Content.toString()); + retrieved.clear(); } catch(const PDNSException& e) { cerr<<"Had error: "<