From 7ef6022899d9fc0febf55024d0125ae4b0008eae Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Fri, 19 Jan 2018 23:23:44 +0100 Subject: [PATCH] Warn when no rule was matched by uuid in rm...Rule() --- pdns/dnsdist-lua-rules.cc | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index 66c7955cd..f2b836620 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -950,10 +950,12 @@ void setupLuaRules() if (auto str = boost::get(&id)) { boost::uuids::string_generator gen; const auto uuid = gen(*str); - rules.erase(std::remove_if(rules.begin(), - rules.end(), - [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }), - rules.end()); + if (rules.erase(std::remove_if(rules.begin(), + rules.end(), + [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }), + rules.end()) == rules.end()) { + g_outputBuffer = "Error: no rule matched\n"; + } } else if (auto pos = boost::get(&id)) { if (*pos >= rules.size()) { @@ -1024,10 +1026,12 @@ void setupLuaRules() if (auto str = boost::get(&id)) { boost::uuids::string_generator gen; const auto uuid = gen(*str); - rules.erase(std::remove_if(rules.begin(), - rules.end(), - [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }), - rules.end()); + if (rules.erase(std::remove_if(rules.begin(), + rules.end(), + [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }), + rules.end()) == rules.end()) { + g_outputBuffer = "Error: no rule matched\n"; + } } else if (auto pos = boost::get(&id)) { if (*pos >= rules.size()) { @@ -1075,10 +1079,12 @@ void setupLuaRules() if (auto str = boost::get(&id)) { boost::uuids::string_generator gen; const auto uuid = gen(*str); - rules.erase(std::remove_if(rules.begin(), - rules.end(), - [uuid](const DNSDistRuleAction& a) { return a.d_id == uuid; }), - rules.end()); + if (rules.erase(std::remove_if(rules.begin(), + rules.end(), + [uuid](const DNSDistRuleAction& a) { return a.d_id == uuid; }), + rules.end()) == rules.end()) { + g_outputBuffer = "Error: no rule matched\n"; + } } else if (auto pos = boost::get(&id)) { if (*pos >= rules.size()) { -- 2.40.0