]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: New Coverity Variable copied when it could be moved cases 15050/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 17 Jan 2025 13:29:13 +0000 (14:29 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 17 Jan 2025 14:38:18 +0000 (15:38 +0100)
Coverity:
1587816
1587811,12,13,14,17,19
1587810
1587809
1587808
1587807
1587806
1587805
1587804
1587801
1587798
1587796
1587795
1587792
1587791
1587790
1587789
1587788
1587786
1544953

14 files changed:
pdns/arguments.cc
pdns/dnsparser.cc
pdns/dnsrecords.cc
pdns/rcpgenerator.cc
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/pubsuffixloader.cc
pdns/recursordist/rec-lua-conf.cc
pdns/recursordist/rec-zonetocache.cc
pdns/recursordist/rec_channel_rec.cc
pdns/recursordist/reczones.cc
pdns/recursordist/settings/generate.py
pdns/recursordist/syncres.cc
pdns/recursordist/validate-recursor.cc

index 7eef549ded369fcfecc1555a7e8f3505e12f2bc5..2e0ae78692647fc71d28fa1bc6d18aa44319c909 100644 (file)
@@ -433,7 +433,7 @@ void ArgvMap::parseOne(const string& arg, const string& parseOnly, bool lax)
       }
       else {
         d_params[var] = val;
-        d_cleared.insert(var);
+        d_cleared.insert(std::move(var));
       }
     }
     else {
index 12974ae57cea70ad50361f967ed89aa271396f53..0c1fce359b36dcdb425cf6fcbcda76d5790dce26 100644 (file)
@@ -631,7 +631,7 @@ void PacketReader::xfrSvcParamKeyVals(set<SvcParam> &kvs) {
           throw std::out_of_range("alpn length of 0");
         }
         xfrBlob(alpn, alpnLen);
-        alpns.push_back(alpn);
+        alpns.push_back(std::move(alpn));
       }
       kvs.insert(SvcParam(key, std::move(alpns)));
       break;
@@ -672,7 +672,7 @@ void PacketReader::xfrSvcParamKeyVals(set<SvcParam> &kvs) {
       bool doAuto{d_internal && len == 0};
       auto param = SvcParam(key, std::move(addresses));
       param.setAutoHint(doAuto);
-      kvs.insert(param);
+      kvs.insert(std::move(param));
       break;
     }
     case SvcParam::ech: {
index 9cabe90ff2f1a4e083e11015b6e5ff77ede1af02..e096be81ef7fed6da40ee39a97fdea52cbd84ec5 100644 (file)
@@ -780,7 +780,7 @@ void SVCBBaseRecordContent::setHints(const SvcParam::SvcParamKey &key, const std
   try {
     auto newParam = SvcParam(key, std::move(h));
     d_params.erase(p);
-    d_params.insert(newParam);
+    d_params.insert(std::move(newParam));
   } catch (...) {
     // XXX maybe we should SERVFAIL instead?
     return;
index 3258fb4afb407713ad7e8bd7530110be1c01846e..fb5869dd126df3b85bfea24cfb51b46c0c814568 100644 (file)
@@ -408,7 +408,7 @@ void RecordTextReader::xfrSvcParamKeyVals(set<SvcParam>& val) // NOLINT(readabil
       try {
         auto p = SvcParam(key, std::move(hints));
         p.setAutoHint(doAuto);
-        val.insert(p);
+        val.insert(std::move(p));
       }
       catch (const std::invalid_argument& e) {
         throw RecordTextException(e.what());
@@ -880,7 +880,7 @@ void RecordTextWriter::xfrSVCBValueList(const vector<string> &val) {
       }
       unescaped += ch;
     }
-    escaped.push_back(unescaped);
+    escaped.push_back(std::move(unescaped));
   }
   if (shouldQuote) {
     d_string.append(1, '"');
index 435c7797296c8b1238a01902d747952007097dd3..4f16b6368428518d86e341898abbf0869ea0a4d9 100644 (file)
@@ -139,7 +139,7 @@ void RecursorLua4::DNSQuestion::addRecord(uint16_t type, const std::string& cont
   dnsRecord.d_type = type;
   dnsRecord.d_place = place;
   dnsRecord.setContent(DNSRecordContent::make(type, QClass::IN, content));
-  records.push_back(dnsRecord);
+  records.push_back(std::move(dnsRecord));
 }
 
 void RecursorLua4::DNSQuestion::addAnswer(uint16_t type, const std::string& content, boost::optional<int> ttl, boost::optional<string> name)
index da7faf5e519805789b630b0d90e667ac27277b7b..559ff7aa06c0f9459a32c960c668ab575a4e6e74 100644 (file)
@@ -814,7 +814,7 @@ int getFakePTRRecords(const DNSName& qname, vector<DNSRecord>& ret)
   record.setContent(std::make_shared<CNAMERecordContent>(newquery));
   // Copy the TTL of the synthesized CNAME from the actual answer
   record.d_ttl = (rcode == RCode::NoError && !answers.empty()) ? answers.at(0).d_ttl : SyncRes::s_minimumTTL;
-  ret.push_back(record);
+  ret.push_back(std::move(record));
 
   ret.insert(ret.end(), answers.begin(), answers.end());
 
index 3d413d66c9a307400a981c21dde700581b9c214c..1174a82c56d20b72ec6528d14fbb8b0882c78806 100644 (file)
@@ -86,7 +86,7 @@ void initPublicSuffixList(const std::string& file)
       vector<string> parts;
       stringtok(parts, low, ".");
       reverse(parts.begin(), parts.end());
-      pbList.push_back(parts);
+      pbList.push_back(std::move(parts));
     }
   }
 
index d25c528f66f9f99fd3114dc91ca6fca324000f80..d4a84532cf6b62b08383831b1d618c66b0a18da2 100644 (file)
@@ -809,7 +809,7 @@ void loadRecursorLuaConfig(const std::string& fname, ProxyMapping& proxyMapping,
 
   try {
     Lua->executeCode(ifs);
-    newLuaConfig = lci;
+    newLuaConfig = std::move(lci);
   }
   catch (const LuaContext::ExecutionErrorException& e) {
     SLOG(g_log << Logger::Error << "Unable to load Lua script from '" + fname + "': ",
index 2c667c2ed0fa44a96f5b5c23f619b75dceb443af..4833f8ac7c40a25a552bb975e4a87368478b08dc 100644 (file)
@@ -99,7 +99,7 @@ void ZoneData::parseDRForCache(DNSRecord& dnsRecord)
   case QType::NSEC3:
     break;
   case QType::RRSIG: {
-    const auto rrsig = getRR<RRSIGRecordContent>(dnsRecord);
+    auto rrsig = getRR<RRSIGRecordContent>(dnsRecord);
     if (rrsig == nullptr) {
       break;
     }
@@ -110,7 +110,7 @@ void ZoneData::parseDRForCache(DNSRecord& dnsRecord)
     }
     else {
       vector<shared_ptr<const RRSIGRecordContent>> sigsrr;
-      sigsrr.push_back(rrsig);
+      sigsrr.push_back(std::move(rrsig));
       d_sigs.insert({sigkey, sigsrr});
     }
     break;
index d79e4c2d04c088f92065e98521ea35da83c6a1aa..76fa3a6015e9d5ca3219da9e9561f5b83fa1fc06 100644 (file)
@@ -1561,7 +1561,7 @@ DNSName getRegisteredName(const DNSName& dom)
   while (!parts.empty()) {
     if (parts.size() == 1 || binary_search(g_pubs.begin(), g_pubs.end(), parts)) {
 
-      string ret = last;
+      string ret = std::move(last);
       if (!ret.empty())
         ret += ".";
 
@@ -1643,7 +1643,7 @@ static string addDontThrottleNames(T begin, T end)
   while (begin != end) {
     try {
       auto d = DNSName(*begin);
-      toAdd.push_back(d);
+      toAdd.push_back(std::move(d));
     }
     catch (const std::exception& e) {
       return "Problem parsing '" + *begin + "': " + e.what() + ", nothing added\n";
@@ -1936,7 +1936,7 @@ RecursorControlChannel::Answer luaconfig(bool broadcast)
       lci = g_luaconfs.getCopy();
       if (broadcast) {
         startLuaConfigDelayedThreads(lci, lci.generation);
-        broadcastFunction([=] { return pleaseSupplantProxyMapping(proxyMapping); });
+        broadcastFunction([pmap = std::move(proxyMapping)] { return pleaseSupplantProxyMapping(pmap); });
       }
       else {
         // Initial proxy mapping
index f015b9dde2026f826573e452db2f656503c26051..ff3fbeeabda3e0f98c1f2ed599d5da9052d027e2 100644 (file)
@@ -208,8 +208,8 @@ string reloadZoneConfiguration(bool yaml)
     // these explicitly-named captures should not be necessary, as lambda
     // capture of tuple-like structured bindings is permitted, but some
     // compilers still don't allow it
-    broadcastFunction([dmap = newDomainMap] { return pleaseUseNewSDomainsMap(dmap); });
-    broadcastFunction([nsset = newNotifySet] { return pleaseSupplantAllowNotifyFor(nsset); });
+    broadcastFunction([dmap = std::move(newDomainMap)] { return pleaseUseNewSDomainsMap(dmap); });
+    broadcastFunction([nsset = std::move(newNotifySet)] { return pleaseSupplantAllowNotifyFor(nsset); });
 
     // Wipe the caches *after* the new auth domain info has been set
     // up, as a query during setting up might fill the caches
index 855678518364a6f06a7cfc59ad5ee3313b13645d..d1e53e26d07d38e731d5015865181d2c477c0fb6 100644 (file)
@@ -316,7 +316,7 @@ def gen_cxx_oldkvtobridgestruct(file, entries):
     file.write('const std::string& value, ::rust::String& section, ::rust::String& fieldname, ')
     file.write('::rust::String& type_name, pdns::rust::settings::rec::Value& rustvalue)')
     file.write('{ // NOLINT(readability-function-cognitive-complexity)\n')
-    file.write('  if (const auto newname = arg().isDeprecated(key); !newname.empty()) {\n')
+    file.write('  if (const auto& newname = arg().isDeprecated(key); !newname.empty()) {\n')
     file.write('    key = newname;\n')
     file.write('  }\n')
     for entry in entries:
index 5bfc4d6740135a86d6d452fe1512f0da54762139..f19e45853900775a1dc9f221f4a3cf10ad9147c9 100644 (file)
@@ -942,7 +942,7 @@ void SyncRes::AuthDomain::addSOA(std::vector<DNSRecord>& records) const
   if (ziter != d_records.end()) {
     DNSRecord dnsRecord = *ziter;
     dnsRecord.d_place = DNSResourceRecord::AUTHORITY;
-    records.push_back(dnsRecord);
+    records.push_back(std::move(dnsRecord));
   }
 }
 
@@ -1028,7 +1028,7 @@ int SyncRes::AuthDomain::getRecords(const DNSName& qname, const QType qtype, std
       if (dnsRecord.d_type == qtype || qtype == QType::ANY || dnsRecord.d_type == QType::CNAME) {
         dnsRecord.d_name = qname;
         dnsRecord.d_place = DNSResourceRecord::ANSWER;
-        records.push_back(dnsRecord);
+        records.push_back(std::move(dnsRecord));
       }
     }
 
@@ -2592,7 +2592,7 @@ bool SyncRes::doCNAMECacheCheck(const DNSName& qname, const QType qtype, vector<
         break;
       }
       if (g_recCache->get(d_now.tv_sec, dnameName, QType::DNAME, flags, &cset, d_cacheRemote, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &context.state, &wasAuth, &authZone, &d_fromAuthIP) > 0) {
-        foundName = dnameName;
+        foundName = std::move(dnameName);
         foundQT = QType::DNAME;
         break;
       }
@@ -2664,13 +2664,13 @@ bool SyncRes::doCNAMECacheCheck(const DNSName& qname, const QType qtype, vector<
           sigdr.setContent(signature);
           sigdr.d_place = DNSResourceRecord::ANSWER;
           sigdr.d_class = QClass::IN;
-          ret.push_back(sigdr);
+          ret.push_back(std::move(sigdr));
         }
 
         for (const auto& rec : *authorityRecs) {
           DNSRecord authDR(rec);
           authDR.d_ttl = ttl;
-          ret.push_back(authDR);
+          ret.push_back(std::move(authDR));
         }
       }
 
@@ -3099,7 +3099,7 @@ bool SyncRes::doCacheCheck(const DNSName& qname, const DNSName& authname, bool w
       dnsRecord.setContent(signature);
       dnsRecord.d_place = DNSResourceRecord::ANSWER;
       dnsRecord.d_class = QClass::IN;
-      ret.push_back(dnsRecord);
+      ret.push_back(std::move(dnsRecord));
     }
 
     for (const auto& rec : *authorityRecs) {
@@ -4025,7 +4025,7 @@ vState SyncRes::getDNSKeys(const DNSName& signer, skeyset_t& keys, bool& servFai
         if (key.d_type == QType::DNSKEY) {
           auto content = getRR<DNSKEYRecordContent>(key);
           if (content) {
-            keys.insert(content);
+            keys.insert(std::move(content));
           }
         }
       }
@@ -4246,7 +4246,7 @@ static void allowAdditionalEntry(std::unordered_set<DNSName>& allowedAdditionals
         if (target.isRoot()) {
           target = rec.d_name;
         }
-        allowedAdditionals.insert(target);
+        allowedAdditionals.insert(std::move(target));
       }
       else {
         // FIXME: Alias mode not implemented yet
@@ -4710,7 +4710,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, const string&
         tcache[{rec.d_name, rec.d_type, rec.d_place}].d_ttl_time = d_now.tv_sec;
         dnsRecord.d_ttl += d_now.tv_sec;
         dnsRecord.d_place = DNSResourceRecord::ANSWER;
-        tcache[{rec.d_name, rec.d_type, rec.d_place}].records.push_back(dnsRecord);
+        tcache[{rec.d_name, rec.d_type, rec.d_place}].records.push_back(std::move(dnsRecord));
       }
     }
     else
index 7c169f27bc8a75bd463655af7e0028ca963f445c..ebf869547e58bd7e673782c4ac459fe7fc9e9cd9 100644 (file)
@@ -65,7 +65,7 @@ bool updateTrustAnchorsFromFile(const std::string& fname, map<DNSName, dsset_t>&
           throw PDNSException("Unable to parse DNSKEY record '" + resourceRecord.qname.toString() + " " + resourceRecord.getZoneRepresentation() + "'");
         }
         auto dsr = makeDSFromDNSKey(resourceRecord.qname, *dnskeyr, DNSSECKeeper::DIGEST_SHA256);
-        newDSAnchors[resourceRecord.qname].insert(dsr);
+        newDSAnchors[resourceRecord.qname].insert(std::move(dsr));
       }
     }
     if (dsAnchors == newDSAnchors) {