]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix the removal of the last rule by name or UUID
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 14 Nov 2023 09:20:43 +0000 (10:20 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 12 Dec 2023 10:32:54 +0000 (11:32 +0100)
(cherry picked from commit 26fb52245b02022f50ab138dfcde4140bd2f707f)

pdns/dnsdist-lua-rules.cc

index 47639365d9caca4d660d14d7349c1e210ed5131f..be899d6f6235706232ffc9ac3ce250c83e34b403 100644 (file)
@@ -130,23 +130,27 @@ static void rmRule(GlobalStateHolder<vector<T> > *someRuleActions, boost::varian
   if (auto str = boost::get<std::string>(&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<unsigned int>(&id)) {