From 46817cd2f39fdf3ddf628f22529b8e5f142f9aa2 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 3 Apr 2020 11:26:18 +0200 Subject: [PATCH] Better test setup and also log if we hit the limit --- pdns/recursordist/test-syncres_cc2.cc | 62 ++++++++++++++++----------- pdns/syncres.cc | 8 ++-- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/pdns/recursordist/test-syncres_cc2.cc b/pdns/recursordist/test-syncres_cc2.cc index 3e8d15917f..3bc3d59e54 100644 --- a/pdns/recursordist/test-syncres_cc2.cc +++ b/pdns/recursordist/test-syncres_cc2.cc @@ -5,7 +5,7 @@ BOOST_AUTO_TEST_SUITE(syncres_cc2) -BOOST_AUTO_TEST_CASE(test_referral_depth) +void do_test_referral_depth(bool limited) { std::unique_ptr sr; initSR(sr); @@ -54,32 +54,46 @@ BOOST_AUTO_TEST_CASE(test_referral_depth) return 0; }); - /* Set the maximum depth low */ - SyncRes::s_maxdepth = 10; - - try { - vector ret; - sr->beginResolve(target, QType(QType::A), QClass::IN, ret); - BOOST_CHECK(false); + if (limited) { + /* Set the maximum depth low */ + SyncRes::s_maxdepth = 10; + try { + vector ret; + sr->beginResolve(target, QType(QType::A), QClass::IN, ret); + BOOST_CHECK(false); + } + catch (const ImmediateServFailException& e) { + BOOST_CHECK(e.reason.find("max-recursion-depth") != string::npos); + } } - catch (const ImmediateServFailException& e) { - BOOST_CHECK(e.reason.find("max-recursion-depth") != string::npos); + else { + // Check if the setup with high limit is OK. + SyncRes::s_maxdepth = 50; + try { + vector ret; + int rcode = sr->beginResolve(target, QType(QType::A), QClass::IN, ret); + BOOST_CHECK_EQUAL(rcode, RCode::NoError); + BOOST_REQUIRE_EQUAL(ret.size(), 1U); + BOOST_CHECK_EQUAL(ret[0].d_name, target); + BOOST_REQUIRE(ret[0].d_type == QType::A); + BOOST_CHECK(getRR(ret[0])->getCA() == ComboAddress("192.0.2.2")); + } + catch (const ImmediateServFailException& e) { + BOOST_CHECK(false); + } } +} - // Then check if the setup with high limit is OK. - SyncRes::s_maxdepth = 50; - try { - vector ret; - int rcode = sr->beginResolve(target, QType(QType::A), QClass::IN, ret); - BOOST_CHECK_EQUAL(rcode, RCode::NoError); - BOOST_CHECK_EQUAL(ret.size(), 1U); - BOOST_CHECK_EQUAL(ret[0].d_name, target); - BOOST_REQUIRE(ret[0].d_type == QType::A); - BOOST_CHECK(getRR(ret[0])->getCA() == ComboAddress("192.0.2.2")); - } - catch (const ImmediateServFailException& e) { - BOOST_CHECK(false); - } +BOOST_AUTO_TEST_CASE(test_referral_depth) +{ + // Test with limit + do_test_referral_depth(true); +} + +BOOST_AUTO_TEST_CASE(test_referral_depth_ok) +{ + // Test with default limit + do_test_referral_depth(false); } BOOST_AUTO_TEST_CASE(test_cname_qperq) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 024cf09efa..2d8e791b8e 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -782,9 +782,11 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType &qty state = Indeterminate; - if(s_maxdepth && depth > s_maxdepth) - throw ImmediateServFailException("More than "+std::to_string(s_maxdepth)+" (max-recursion-depth) levels of recursion needed while resolving "+qname.toLogString()); - + if (s_maxdepth && depth > s_maxdepth) { + string msg = "More than " + std::to_string(s_maxdepth) + " (max-recursion-depth) levels of recursion needed while resolving " + qname.toLogString(); + LOG(prefix << qname << ": " << msg << endl); + throw ImmediateServFailException(msg); + } int res=0; // This is a difficult way of expressing "this is a normal query", i.e. not getRootNS. -- 2.47.2