From f4921608bcc89e2363d3c202ada2fdb1552410a9 Mon Sep 17 00:00:00 2001 From: sproxet Date: Thu, 15 Dec 2022 13:30:29 +0700 Subject: [PATCH] Fix Various Instances of Undefined Behaviour (#1198) * Fix UB in bls. * Fix UB in CDKGSessionHandler::SleepBeforePhase. * Fix UB in CQuorumBlockProcessor::GetCommitmentsFromBlock. --- src/bls/bls.h | 2 +- src/llmq/quorums_blockprocessor.cpp | 3 ++- src/llmq/quorums_dkgsessionhandler.cpp | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bls/bls.h b/src/bls/bls.h index f4ccb17f5c..6330d0f95c 100644 --- a/src/bls/bls.h +++ b/src/bls/bls.h @@ -42,7 +42,7 @@ class CBLSWrapper friend class CBLSPublicKey; friend class CBLSSignature; - bool fLegacy; + bool fLegacy{fLegacyDefault}; protected: ImplType impl; diff --git a/src/llmq/quorums_blockprocessor.cpp b/src/llmq/quorums_blockprocessor.cpp index c24170c283..796fff6fb2 100644 --- a/src/llmq/quorums_blockprocessor.cpp +++ b/src/llmq/quorums_blockprocessor.cpp @@ -321,7 +321,8 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, const C return state.DoS(100, false, REJECT_INVALID, "bad-qc-dup"); } - ret.emplace((Consensus::LLMQType)qc.commitment.llmqType, std::move(qc.commitment)); + auto llmqTypeTemp = (Consensus::LLMQType)qc.commitment.llmqType; + ret.emplace(llmqTypeTemp, std::move(qc.commitment)); } } diff --git a/src/llmq/quorums_dkgsessionhandler.cpp b/src/llmq/quorums_dkgsessionhandler.cpp index e472ac5de0..fe3bde4746 100644 --- a/src/llmq/quorums_dkgsessionhandler.cpp +++ b/src/llmq/quorums_dkgsessionhandler.cpp @@ -238,7 +238,8 @@ void CDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase, phaseTime = 0; } - int64_t sleepTime = (int64_t)(phaseTime * curSession->GetMyMemberIndex()); + int64_t sleepTime = 0; + if (curSession->GetMyMemberIndex() != UINT64_MAX) sleepTime = (int64_t)(phaseTime * curSession->GetMyMemberIndex()); int64_t endTime = GetTimeMillis() + sleepTime; while (GetTimeMillis() < endTime) { if (stopRequested || ShutdownRequested()) {