]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Another set of coverity fixes, these are a bit more tricky
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 20 Nov 2023 16:15:53 +0000 (17:15 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 21 Nov 2023 10:05:08 +0000 (11:05 +0100)
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/rpzloader.cc

index 985f9bf043c4a02edc78b8c997e4fa1deef4e439..fc08701f3d44cae13eea749e496abf10fb47a571 100644 (file)
@@ -293,7 +293,7 @@ void RecursorLua4::postPrepareContext()
       return ret;
     });
 
-  d_lw->registerFunction<const ProxyProtocolValue, std::string()>("getContent", [](const ProxyProtocolValue& value) { return value.content; });
+  d_lw->registerFunction<const ProxyProtocolValue, std::string()>("getContent", [](const ProxyProtocolValue& value) -> std::string { return value.content; });
   d_lw->registerFunction<const ProxyProtocolValue, uint8_t()>("getType", [](const ProxyProtocolValue& value) { return value.type; });
 
   d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.setContent(DNSRecordContent::make(dr.d_type, QClass::IN, newContent)); });
@@ -637,7 +637,7 @@ unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& edn
 
     auto ret = d_gettag(remote, ednssubnet, local, qname, qtype, ednsOptions, tcp, proxyProtocolValuesMap);
 
-    if (policyTags) {
+    if (policyTags != nullptr) {
       const auto& tags = std::get<1>(ret);
       if (tags) {
         policyTags->reserve(policyTags->size() + tags->size());
@@ -646,25 +646,25 @@ unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& edn
         }
       }
     }
-    const auto dataret = std::get<2>(ret);
+    const auto& dataret = std::get<2>(ret);
     if (dataret) {
       data = *dataret;
     }
-    const auto reqIdret = std::get<3>(ret);
+    const auto& reqIdret = std::get<3>(ret);
     if (reqIdret) {
       requestorId = *reqIdret;
     }
-    const auto deviceIdret = std::get<4>(ret);
+    const auto& deviceIdret = std::get<4>(ret);
     if (deviceIdret) {
       deviceId = *deviceIdret;
     }
 
-    const auto deviceNameret = std::get<5>(ret);
+    const auto& deviceNameret = std::get<5>(ret);
     if (deviceNameret) {
       deviceName = *deviceNameret;
     }
 
-    const auto routingTarget = std::get<6>(ret);
+    const auto& routingTarget = std::get<6>(ret);
     if (routingTarget) {
       routingTag = *routingTarget;
     }
@@ -745,7 +745,8 @@ bool RecursorLua4::genhook(const luacall_t& func, DNSQuestion& dq, int& ret) con
       else if (dq.followupFunction == "udpQueryResponse") {
         PacketBuffer p = GenUDPQueryResponse(dq.udpQueryDest, dq.udpQuery);
         dq.udpAnswer = std::string(reinterpret_cast<const char*>(p.data()), p.size());
-        auto cbFunc = d_lw->readVariable<boost::optional<luacall_t>>(dq.udpCallback).get_value_or(0);
+        // coverity[auto_causes_copy] not copying produces a dangling ref
+        const auto cbFunc = d_lw->readVariable<boost::optional<luacall_t>&>(dq.udpCallback).get_value_or(nullptr);
         if (!cbFunc) {
           SLOG(g_log << Logger::Error << "Attempted callback for Lua UDP Query/Response which could not be found" << endl,
                g_slog->withName("lua")->info(Logr::Error, "Attempted callback for Lua UDP Query/Response which could not be found"));
index 62368bb519d4ed74cba558166a91d75447029c99..549902c0586db126ddd0dc84e5b6a2dafe5b1114 100644 (file)
@@ -307,7 +307,7 @@ std::shared_ptr<const SOARecordContent> loadRPZFromFile(const std::string& fname
         sr = getRR<SOARecordContent>(dr);
         domain = dr.d_name;
         zone->setDomain(domain);
-        soaRecord = dr;
+        soaRecord = std::move(dr);
       }
       else if (dr.d_type == QType::NS) {
         continue;
@@ -324,7 +324,7 @@ std::shared_ptr<const SOARecordContent> loadRPZFromFile(const std::string& fname
 
   if (sr != nullptr) {
     zone->setRefresh(sr->d_st.refresh);
-    zone->setSOA(soaRecord);
+    zone->setSOA(std::move(soaRecord));
     setRPZZoneNewState(zone->getName(), sr->d_st.serial, zone->size(), true, false);
   }
   return sr;
@@ -568,7 +568,7 @@ void RPZIXFRTracker(const std::vector<ComboAddress>& primaries, const boost::opt
             auto tempSR = getRR<SOARecordContent>(rr);
             //   g_log<<Logger::Info<<"New SOA serial for "<<zoneName<<": "<<currentSR->d_st.serial<<endl;
             if (tempSR) {
-              currentSR = tempSR;
+              currentSR = std::move(tempSR);
             }
           }
           else {
@@ -582,7 +582,7 @@ void RPZIXFRTracker(const std::vector<ComboAddress>& primaries, const boost::opt
 
       /* only update sr now that all changes have been converted */
       if (currentSR) {
-        sr = currentSR;
+        sr = std::move(currentSR);
       }
       SLOG(g_log << Logger::Info << "Had " << totremove << " RPZ removal" << addS(totremove) << ", " << totadd << " addition" << addS(totadd) << " for " << zoneName << " New serial: " << sr->d_st.serial << endl,
            logger->info(Logr::Info, "RPZ mutations", "removals", Logging::Loggable(totremove), "additions", Logging::Loggable(totadd), "newserial", Logging::Loggable(sr->d_st.serial)));