]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix a few warnings from Coverity 15198/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 21 Feb 2025 10:44:18 +0000 (11:44 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 21 Feb 2025 10:44:18 +0000 (11:44 +0100)
Mostly missed optimizations in places where the performance does not
matter much (configuration parsing) and a few false positives
(places where a copy is actually what we want, and Coverity is not
smart enough to understand it).

pdns/dnsdistdist/bpf-filter.cc
pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc
pdns/dnsdistdist/dnsdist-lua-inspection.cc
pdns/dnsdistdist/dnsdist-lua-rules.cc
pdns/dnsdistdist/dnsdist-lua.cc
pdns/dnsdistdist/dnsdist-metrics.cc
pdns/dnsdistdist/dnsdist-protobuf.cc

index bfed7cfc11196672d72dd0acac7e7ea3a9ddd348..afe9ff60216a98236486e780e2f663bca9a3e8c5 100644 (file)
@@ -974,9 +974,10 @@ bool BPFFilter::supportsMatchAction(MatchAction action) const
     return true;
   }
   return d_mapFormat == BPFFilter::MapFormat::WithActions;
-#endif /* HAVE_EBPF */
+#else
   (void)action;
   return false;
+#endif /* HAVE_EBPF */
 }
 
 bool BPFFilter::isExternal() const
index 6ddd0779e2c3137746822dc1d91147c9644acac3..5c6530dca0a809c90689254614c0a67738eb03fc 100644 (file)
@@ -207,6 +207,7 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
       return empty;
     }
 
+    // coverity[auto_causes_copy]
     return *dnsQuestion.ids.qTag;
   });
 
@@ -552,9 +553,11 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
 
   luaCtx.registerFunction<LuaAssociativeTable<std::string> (DNSQuestion::*)(void) const>("getHTTPHeaders", [](const DNSQuestion& dnsQuestion) {
     if (dnsQuestion.ids.du) {
+      // coverity[auto_causes_copy]
       return dnsQuestion.ids.du->getHTTPHeaders();
     }
     if (dnsQuestion.ids.doh3u) {
+      // coverity[auto_causes_copy]
       return dnsQuestion.ids.doh3u->getHTTPHeaders();
     }
     return LuaAssociativeTable<std::string>();
index 77ee1e2671c250b9bdcb6bd76daaf4db97b209f2..95be35ad37cbf77a25d660ece66668deee1cbdf9 100644 (file)
@@ -715,7 +715,7 @@ void setupLuaInspection(LuaContext& luaCtx)
     for (const auto& entry : histo) {
       int stars = static_cast<int>(70.0 * entry.second / highest);
       char value = '*';
-      if (stars == 0 && entry.second != 0) {
+      if (stars == 0 && entry.second != 0 && highest != 0.0) {
         stars = 1; // you get 1 . to show something is there..
         if (70.0 * entry.second / highest > 0.5) {
           value = ':';
index 44942e902f338ad8d99bf252731a1834093bf230..e4367c3fbfe7ffca7d51d1cbc718ea8c8171a917 100644 (file)
@@ -233,7 +233,7 @@ static void mvRule(IdentifierTypeT chainIdentifier, unsigned int from, unsigned
     auto subject = rules[from];
     rules.erase(rules.begin() + from);
     if (destination > rules.size()) {
-      rules.push_back(subject);
+      rules.push_back(std::move(subject));
     }
     else {
       if (from < destination) {
index 162161072c19df57b768b69b8430bea2eaefca16..25cc2e2859391c21c85d77ab0fa3f68f436dd080 100644 (file)
@@ -2226,7 +2226,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
       if (getOptionalValue<decltype(customResponseHeaders)>(vars, "customResponseHeaders", customResponseHeaders) > 0) {
         for (auto const& headerMap : customResponseHeaders) {
           auto headerResponse = std::pair(boost::to_lower_copy(headerMap.first), headerMap.second);
-          frontend->d_customResponseHeaders.insert(headerResponse);
+          frontend->d_customResponseHeaders.insert(std::move(headerResponse));
         }
       }
 
@@ -3082,7 +3082,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
         checkAllParametersConsumed("declareMetric", vars);
       }
     }
-    auto result = dnsdist::metrics::declareCustomMetric(name, type, description, customName, withLabels);
+    auto result = dnsdist::metrics::declareCustomMetric(name, type, description, std::move(customName), withLabels);
     if (result) {
       g_outputBuffer += *result + "\n";
       errlog("Error in declareMetric: %s", *result);
index 293be6d95c4d5b8b94117248a59f86d99837115f..80538b56669a96ed8c62b4e861fca4659ecda200 100644 (file)
@@ -242,7 +242,7 @@ static T& initializeOrGetMetric(const std::string_view& name, std::map<std::stri
   auto metricEntry = metricEntries.find(combinationOfLabels);
   if (metricEntry == metricEntries.end()) {
     metricEntry = metricEntries.emplace(std::piecewise_construct, std::forward_as_tuple(combinationOfLabels), std::forward_as_tuple()).first;
-    g_stats.entries.write_lock()->emplace_back(Stats::EntryTriple{std::string(name), combinationOfLabels, &metricEntry->second.d_value});
+    g_stats.entries.write_lock()->emplace_back(Stats::EntryTriple{std::string(name), std::move(combinationOfLabels), &metricEntry->second.d_value});
   }
   return metricEntry->second;
 }
index d3b9200dc7c20e77f4a7fd2ce05db2998306c328..b5fca511c193fb4a7356ebf3c61c144bfbd48e0b 100644 (file)
@@ -260,7 +260,7 @@ ProtoBufMetaKey::ProtoBufMetaKey(const std::string& key)
           if (!typeIt->d_caseSensitive) {
             boost::algorithm::to_lower(variable);
           }
-          d_subKey = variable;
+          d_subKey = std::move(variable);
         }
         return;
       }
@@ -383,7 +383,7 @@ const ProtoBufMetaKey::TypeContainer ProtoBufMetaKey::s_types = {
                                             auto tag = key;
                                             tag.append(":");
                                             tag.append(value);
-                                            result.push_back(tag);
+                                            result.push_back(std::move(tag));
                                           }
                                         }
                                         return result;