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: dnsdist-1.8.3~7^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ffcfb7a7da26150238a7d050e12b435ab8d4a26;p=thirdparty%2Fpdns.git dnsdist: Fix the removal of the last rule by name or UUID (cherry picked from commit 26fb52245b02022f50ab138dfcde4140bd2f707f) --- diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index 47639365d9..be899d6f62 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -130,23 +130,27 @@ static void rmRule(GlobalStateHolder > *someRuleActions, boost::varian 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)) {