From: Remi Gacogne Date: Tue, 14 Nov 2023 09:20:43 +0000 (+0100) Subject: dnsdist: Fix the removal of the last rule by name or UUID X-Git-Tag: rec-5.0.0-rc1~41^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26fb52245b02022f50ab138dfcde4140bd2f707f;p=thirdparty%2Fpdns.git dnsdist: Fix the removal of the last rule by name or UUID --- diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index 2495b4a9ee..63beb7220c 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -131,23 +131,27 @@ static void rmRule(GlobalStateHolder > *someRuleActions, const boost:: if (auto str = boost::get(&id)) { try { const auto uuid = getUniqueID(*str); - if (rules.erase(std::remove_if(rules.begin(), + auto removeIt = std::remove_if(rules.begin(), rules.end(), - [uuid](const T& a) { return a.d_id == uuid; }), - rules.end()) == rules.end()) { + [uuid](const T& rule) { return rule.d_id == uuid; }); + if (removeIt == rules.end()) { g_outputBuffer = "Error: no rule matched\n"; return; } + rules.erase(removeIt, + rules.end()); } catch (const std::runtime_error& e) { /* it was not an UUID, let's see if it was a name instead */ - if (rules.erase(std::remove_if(rules.begin(), + auto removeIt = std::remove_if(rules.begin(), rules.end(), - [&str](const T& a) { return a.d_name == *str; }), - rules.end()) == rules.end()) { + [&str](const T& rule) { return rule.d_name == *str; }); + if (removeIt == rules.end()) { g_outputBuffer = "Error: no rule matched\n"; return; } + rules.erase(removeIt, + rules.end()); } } else if (auto pos = boost::get(&id)) {