diff options
author | John Newbery <john@johnnewbery.com> | 2017-02-15 14:19:16 -0500 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-02-17 09:04:37 +0100 |
commit | 55c403b8febe02555c52bac7028cd6b1f006fad1 (patch) | |
tree | 5c1a5795990b01c47e49a03d3854e2c3a100766c /src/script | |
parent | 476cc47da084633ac17b9b3c9257fab425b3bbba (diff) |
Ensure `-maxsigcachesize` is in valid range
- If the -maxsigcachesize parameter is set to zero, setup a minimum sized
sigcache (2 elements) rather than segfaulting.
- Handle maxsigcachesize being negative
- Handle maxsigcachesize being too large
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/sigcache.cpp | 5 | ||||
-rw-r--r-- | src/script/sigcache.h | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 09bedc5460..6f364e42d1 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -93,8 +93,9 @@ static CSignatureCache signatureCache; // To be called once in AppInit2/TestingSetup to initialize the signatureCache void InitSignatureCache() { - size_t nMaxCacheSize = GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); - if (nMaxCacheSize <= 0) return; + // nMaxCacheSize is unsigned. If -maxsigcachesize is set to zero, + // setup_bytes creates the minimum possible cache (2 elements). + size_t nMaxCacheSize = std::min(std::max((int64_t)0, GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE)), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); size_t nElems = signatureCache.setup_bytes(nMaxCacheSize); LogPrintf("Using %zu MiB out of %zu requested for signature cache, able to store %zu elements\n", (nElems*sizeof(uint256)) >>20, nMaxCacheSize>>20, nElems); diff --git a/src/script/sigcache.h b/src/script/sigcache.h index c123a9ba0f..238952bb95 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -14,6 +14,8 @@ // systems). Due to how we count cache size, actual memory usage is slightly // more (~32.25 MB) static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE = 32; +// Maximum sig cache size allowed +static const int64_t MAX_MAX_SIG_CACHE_SIZE = 16384; class CPubKey; |