fix: potential bug due to unspecified state of std::vector after move

This commit is contained in:
Konstantin Akimov 2024-11-26 01:47:41 +07:00
parent 8a05f0caaa
commit 83e0bb6e35
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
2 changed files with 3 additions and 8 deletions

View File

@ -520,10 +520,8 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify(
void CSigningManager::ProcessPendingReconstructedRecoveredSigs() void CSigningManager::ProcessPendingReconstructedRecoveredSigs()
{ {
decltype(pendingReconstructedRecoveredSigs) m; decltype(pendingReconstructedRecoveredSigs) m;
{ WITH_LOCK(cs_pending, swap(m, pendingReconstructedRecoveredSigs));
LOCK(cs_pending);
m = std::move(pendingReconstructedRecoveredSigs);
}
for (const auto& p : m) { for (const auto& p : m) {
ProcessRecoveredSig(p.second); ProcessRecoveredSig(p.second);
} }

View File

@ -1490,10 +1490,7 @@ void CSigSharesManager::AsyncSign(const CQuorumCPtr& quorum, const uint256& id,
void CSigSharesManager::SignPendingSigShares() void CSigSharesManager::SignPendingSigShares()
{ {
std::vector<PendingSignatureData> v; std::vector<PendingSignatureData> v;
{ WITH_LOCK(cs_pendingSigns, v.swap(pendingSigns));
LOCK(cs_pendingSigns);
v = std::move(pendingSigns);
}
for (const auto& [pQuorum, id, msgHash] : v) { for (const auto& [pQuorum, id, msgHash] : v) {
auto opt_sigShare = CreateSigShare(pQuorum, id, msgHash); auto opt_sigShare = CreateSigShare(pQuorum, id, msgHash);