diff --git a/src/bench/base58.cpp b/src/bench/base58.cpp index 3319c179bf5..70850fe74fb 100644 --- a/src/bench/base58.cpp +++ b/src/bench/base58.cpp @@ -7,20 +7,22 @@ #include "validation.h" #include "base58.h" +#include #include #include static void Base58Encode(benchmark::State& state) { - unsigned char buff[32] = { - 17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147, - 227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90, - 200, 24 + static const std::array buff = { + { + 17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147, + 227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90, + 200, 24 + } }; - unsigned char* b = buff; while (state.KeepRunning()) { - EncodeBase58(b, b + 32); + EncodeBase58(buff.data(), buff.data() + buff.size()); } } diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp index 88a2a570f93..79082290e25 100644 --- a/src/bench/checkqueue.cpp +++ b/src/bench/checkqueue.cpp @@ -19,7 +19,7 @@ static const int MIN_CORES = 2; static const size_t BATCHES = 101; static const size_t BATCH_SIZE = 30; static const int PREVECTOR_SIZE = 28; -static const int QUEUE_BATCH_SIZE = 128; +static const unsigned int QUEUE_BATCH_SIZE = 128; static void CCheckQueueSpeed(benchmark::State& state) { struct FakeJobNoWork { diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 5f8ebaa7af1..3991e245e6f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -459,8 +459,9 @@ class CRegTestParams : public CChainParams { fMineBlocksOnDemand = true; checkpointData = (CCheckpointData){ - boost::assign::map_list_of - ( 0, uint256S("0x3d2160a3b5dc4a9d62e7e66a295f70313ac808440ef7400d6c0772171ce973a5")) + { + {0, uint256S("0x3d2160a3b5dc4a9d62e7e66a295f70313ac808440ef7400d6c0772171ce973a5")}, + } }; chainTxData = ChainTxData{ diff --git a/src/compat.h b/src/compat.h index d4dc3ba9923..6a2cbc5dcb1 100644 --- a/src/compat.h +++ b/src/compat.h @@ -32,6 +32,7 @@ #include #include #include +#include #else #include #include @@ -74,6 +75,15 @@ typedef u_int SOCKET; #else #define MAX_PATH 1024 #endif +#ifdef _MSC_VER +#if !defined(ssize_t) +#ifdef _WIN64 +typedef int64_t ssize_t; +#else +typedef int32_t ssize_t; +#endif +#endif +#endif // As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0 #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) diff --git a/src/random.h b/src/random.h index b35cf51a166..6503d8359f0 100644 --- a/src/random.h +++ b/src/random.h @@ -121,7 +121,7 @@ class FastRandomContext { * sure that the underlying OS APIs for all platforms support the number. * (many cap out at 256 bytes). */ -static const ssize_t NUM_OS_RANDOM_BYTES = 32; +static const int NUM_OS_RANDOM_BYTES = 32; /** Get 32 bytes of system entropy. Do not use this in application code: use * GetStrongRandBytes instead. diff --git a/src/support/cleanse.cpp b/src/support/cleanse.cpp index a2141b24498..eb6e0a73a20 100644 --- a/src/support/cleanse.cpp +++ b/src/support/cleanse.cpp @@ -5,9 +5,39 @@ #include "cleanse.h" -#include +#include +#if defined(_MSC_VER) +#include // For SecureZeroMemory. +#endif + +/* Compilers have a bad habit of removing "superfluous" memset calls that + * are trying to zero memory. For example, when memset()ing a buffer and + * then free()ing it, the compiler might decide that the memset is + * unobservable and thus can be removed. + * + * Previously we used OpenSSL which tried to stop this by a) implementing + * memset in assembly on x86 and b) putting the function in its own file + * for other platforms. + * + * This change removes those tricks in favour of using asm directives to + * scare the compiler away. As best as our compiler folks can tell, this is + * sufficient and will continue to be so. + * + * Adam Langley + * Commit: ad1907fe73334d6c696c8539646c21b11178f20f + * BoringSSL (LICENSE: ISC) + */ void memory_cleanse(void *ptr, size_t len) { - OPENSSL_cleanse(ptr, len); + std::memset(ptr, 0, len); + + /* As best as we can tell, this is sufficient to break any optimisations that + might try to eliminate "superfluous" memsets. If there's an easy way to + detect memset_s, it would be better to use that. */ +#if defined(_MSC_VER) + SecureZeroMemory(ptr, len); +#else + __asm__ __volatile__("" : : "r"(ptr) : "memory"); +#endif } diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 36b8768cd36..34d9bdb6348 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -24,7 +24,7 @@ // otherwise. BOOST_FIXTURE_TEST_SUITE(checkqueue_tests, TestingSetup) -static const int QUEUE_BATCH_SIZE = 128; +static const unsigned int QUEUE_BATCH_SIZE = 128; struct FakeCheck { bool operator()()