From 321bbc2079e2dc3648ae4eaf845f5b71d30b423a Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 10 Feb 2017 18:03:14 -0800 Subject: [PATCH 1/2] fix ubsan: bitcoin-tx: not initialize context before IsFullyValid --- src/bitcoin-tx.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 61e0eb74e6..4b64a96822 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -651,11 +651,13 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command, MutateTxDelOutput(tx, commandVal); else if (command == "outaddr") MutateTxAddOutAddr(tx, commandVal); - else if (command == "outpubkey") + else if (command == "outpubkey") { + if (!ecc) { ecc.reset(new Secp256k1Init()); } MutateTxAddOutPubKey(tx, commandVal); - else if (command == "outmultisig") + } else if (command == "outmultisig") { + if (!ecc) { ecc.reset(new Secp256k1Init()); } MutateTxAddOutMultiSig(tx, commandVal); - else if (command == "outscript") + } else if (command == "outscript") MutateTxAddOutScript(tx, commandVal); else if (command == "outdata") MutateTxAddOutData(tx, commandVal); From 1d31093d4d8501a5dc031413a963707f6cae0e0a Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 11 Feb 2017 12:37:05 -0800 Subject: [PATCH 2/2] fix tsan: utiltime race on nMockTime --- src/utiltime.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utiltime.cpp b/src/utiltime.cpp index a9936a645a..510f540b1d 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -9,14 +9,17 @@ #include "utiltime.h" +#include + #include #include -static int64_t nMockTime = 0; //!< For unit testing +static std::atomic nMockTime(0); //!< For unit testing int64_t GetTime() { - if (nMockTime) return nMockTime; + int64_t mocktime = nMockTime.load(std::memory_order_relaxed); + if (mocktime) return mocktime; time_t now = time(NULL); assert(now > 0); @@ -25,7 +28,7 @@ int64_t GetTime() void SetMockTime(int64_t nMockTimeIn) { - nMockTime = nMockTimeIn; + nMockTime.store(nMockTimeIn, std::memory_order_relaxed); } int64_t GetTimeMillis() @@ -52,7 +55,8 @@ int64_t GetSystemTimeInSeconds() /** Return a time useful for the debug log */ int64_t GetLogTimeMicros() { - if (nMockTime) return nMockTime*1000000; + int64_t mocktime = nMockTime.load(std::memory_order_relaxed); + if (mocktime) return mocktime*1000000; return GetTimeMicros(); }