From: Otto Moerbeek Date: Mon, 20 Nov 2023 16:15:53 +0000 (+0100) Subject: Another set of coverity fixes, these are a bit more tricky X-Git-Tag: dnsdist-1.9.0-alpha4~20^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=50bd111e3c78e2cc8c2aa916a1f9fc22699f1f60;p=thirdparty%2Fpdns.git Another set of coverity fixes, these are a bit more tricky --- diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index 985f9bf043..fc08701f3d 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -293,7 +293,7 @@ void RecursorLua4::postPrepareContext() return ret; }); - d_lw->registerFunction("getContent", [](const ProxyProtocolValue& value) { return value.content; }); + d_lw->registerFunction("getContent", [](const ProxyProtocolValue& value) -> std::string { return value.content; }); d_lw->registerFunction("getType", [](const ProxyProtocolValue& value) { return value.type; }); d_lw->registerFunction("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(p.data()), p.size()); - auto cbFunc = d_lw->readVariable>(dq.udpCallback).get_value_or(0); + // coverity[auto_causes_copy] not copying produces a dangling ref + const auto cbFunc = d_lw->readVariable&>(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")); diff --git a/pdns/recursordist/rpzloader.cc b/pdns/recursordist/rpzloader.cc index 62368bb519..549902c058 100644 --- a/pdns/recursordist/rpzloader.cc +++ b/pdns/recursordist/rpzloader.cc @@ -307,7 +307,7 @@ std::shared_ptr loadRPZFromFile(const std::string& fname sr = getRR(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 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& primaries, const boost::opt auto tempSR = getRR(rr); // g_log<d_st.serial<& 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)));