From 0d4ea1cf8a349cf59795ac68645afe70e98c6b3a Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sat, 3 May 2014 10:20:58 +0200 Subject: util: add parseint32 function with strict error reporting None of the current integer parsing functions in util check whether the result is valid and fits in the range of the type. This is required for less sloppy error reporting. --- src/util.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index a919b4b85..36ac23b1d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1427,3 +1427,17 @@ void RenameThread(const char* name) #endif } +bool ParseInt32(const std::string& str, int32_t *out) +{ + char *endp = NULL; + errno = 0; // strtol will not set errno if valid + long int n = strtol(str.c_str(), &endp, 10); + if(out) *out = (int)n; + // Note that strtol returns a *long int*, so even if strtol doesn't report a over/underflow + // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit + // platforms the size of these types may be different. + return endp && *endp == 0 && !errno && + n >= std::numeric_limits::min() && + n <= std::numeric_limits::max(); +} + -- cgit v1.2.3 From fdbd7075cab8d54f90c038e68afba868a9ff9f63 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 28 Apr 2014 13:48:57 +0200 Subject: Remove unused function WildcardMatch No longer necessary after implementing netmask-based matching. Also remove a longer-unused function `skipspaces`. --- src/util.cpp | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 36ac23b1d..00e29446d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -889,43 +889,6 @@ string DecodeBase32(const string& str) return string((const char*)&vchRet[0], vchRet.size()); } - -bool WildcardMatch(const char* psz, const char* mask) -{ - while (true) - { - switch (*mask) - { - case '\0': - return (*psz == '\0'); - case '*': - return WildcardMatch(psz, mask+1) || (*psz && WildcardMatch(psz+1, mask)); - case '?': - if (*psz == '\0') - return false; - break; - default: - if (*psz != *mask) - return false; - break; - } - psz++; - mask++; - } -} - -bool WildcardMatch(const string& str, const string& mask) -{ - return WildcardMatch(str.c_str(), mask.c_str()); -} - - - - - - - - static std::string FormatException(std::exception* pex, const char* pszThread) { #ifdef WIN32 -- cgit v1.2.3 From be54b87f22f10bf84bc25d9e29bf1eed596dc764 Mon Sep 17 00:00:00 2001 From: Kamil Domanski Date: Tue, 13 May 2014 11:11:02 +0200 Subject: remove ParseString(...) which is never used --- src/util.cpp | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 00e29446d..205af738d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -303,26 +303,6 @@ int LogPrintStr(const std::string &str) return ret; } -void ParseString(const string& str, char c, vector& v) -{ - if (str.empty()) - return; - string::size_type i1 = 0; - string::size_type i2; - while (true) - { - i2 = str.find(c, i1); - if (i2 == str.npos) - { - v.push_back(str.substr(i1)); - return; - } - v.push_back(str.substr(i1, i2-i1)); - i1 = i2+1; - } -} - - string FormatMoney(int64_t n, bool fPlus) { // Note: not using straight sprintf here because we do NOT want -- cgit v1.2.3 From 5248ff40997c64cc0fde7aaa67cf94dd38b14899 Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Tue, 13 May 2014 10:15:00 +0000 Subject: SetupEnvironment() - clean commit --- src/util.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 00e29446d..2e8500eea 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1404,3 +1404,19 @@ bool ParseInt32(const std::string& str, int32_t *out) n <= std::numeric_limits::max(); } +void SetupEnvironment() +{ + #ifndef WIN32 + try + { + #if BOOST_FILESYSTEM_VERSION == 3 + boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid + #else // boost filesystem v2 + std::locale(); // Raises runtime error if current locale is invalid + #endif + } catch(std::runtime_error &e) + { + setenv("LC_ALL", "C", 1); // Force C locale + } + #endif +} -- cgit v1.2.3 From 595f691d0acd871ecaba323d888a3632805c1828 Mon Sep 17 00:00:00 2001 From: Kamil Domanski Date: Tue, 13 May 2014 21:00:16 +0200 Subject: remove LogException( ) which is never used --- src/util.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index aa3adf89e..d99e6a7bf 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -885,12 +885,6 @@ static std::string FormatException(std::exception* pex, const char* pszThread) "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread); } -void LogException(std::exception* pex, const char* pszThread) -{ - std::string message = FormatException(pex, pszThread); - LogPrintf("\n%s", message); -} - void PrintExceptionContinue(std::exception* pex, const char* pszThread) { std::string message = FormatException(pex, pszThread); -- cgit v1.2.3 From 3e8ac6af9a993e262d1160fb2e6e1e1f1d5d19f2 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 8 May 2014 18:01:10 +0200 Subject: Replace non-threadsafe gmtime and setlocale Make DateTimeStrFormat use boost::posix_time. Also re-enable the util_DateTimeStrFormat tests, as they are no longer platform specific. --- src/util.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index aa3adf89e..f7ceb3e95 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -14,6 +14,8 @@ #include +#include + #ifndef WIN32 // for posix_fallocate #ifdef __linux_ @@ -1400,3 +1402,13 @@ void SetupEnvironment() } #endif } + +std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) +{ + // std::locale takes ownership of the pointer + std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat)); + std::stringstream ss; + ss.imbue(loc); + ss << boost::posix_time::from_time_t(nTime); + return ss.str(); +} -- cgit v1.2.3 From 53a088154ce4e1fc483afa120a9063811dd0e7ea Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Thu, 29 May 2014 12:33:17 +0200 Subject: rename fNoListen to fListen and move to net - better code readability and it belongs to net - this is a prerequisite for a pull to add -listen to the GUI --- src/util.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 336ef3172..d106b0323 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -94,7 +94,6 @@ bool fPrintToDebugLog = true; bool fDaemon = false; bool fServer = false; string strMiscWarning; -bool fNoListen = false; bool fLogTimestamps = false; volatile bool fReopenDebugLog = false; CClientUIInterface uiInterface; -- cgit v1.2.3 From 71aaff393f06378150612fc618b6c3f84c1d2066 Mon Sep 17 00:00:00 2001 From: Kosta Zertsekel Date: Wed, 4 Jun 2014 07:36:45 +0300 Subject: Remove double-dash parameters from mapArgs Should be merged after pull request #4281 ("Add `-version` option to get just the version #4281"), because is changed "--help" to "-help". Checked that grep of 'mapArgs.count("--' returned only three places that are fixed by pull request #4281. --- src/util.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 205af738d..752ebb7bf 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -459,6 +459,7 @@ void ParseParameters(int argc, const char* const argv[]) { mapArgs.clear(); mapMultiArgs.clear(); + for (int i = 1; i < argc; i++) { std::string str(argv[i]); @@ -474,9 +475,15 @@ void ParseParameters(int argc, const char* const argv[]) if (boost::algorithm::starts_with(str, "/")) str = "-" + str.substr(1); #endif + if (str[0] != '-') break; + // Interpret --foo as -foo. + // If both --foo and -foo are set, the last takes effect. + if (str.length() > 1 && str[1] == '-') + str = str.substr(1); + mapArgs[str] = strValue; mapMultiArgs[str].push_back(strValue); } @@ -484,19 +491,8 @@ void ParseParameters(int argc, const char* const argv[]) // New 0.6 features: BOOST_FOREACH(const PAIRTYPE(string,string)& entry, mapArgs) { - string name = entry.first; - - // interpret --foo as -foo (as long as both are not set) - if (name.find("--") == 0) - { - std::string singleDash(name.begin()+1, name.end()); - if (mapArgs.count(singleDash) == 0) - mapArgs[singleDash] = entry.second; - name = singleDash; - } - // interpret -nofoo as -foo=0 (and -nofoo=0 as -foo=1) as long as -foo not set - InterpretNegativeSetting(name, mapArgs); + InterpretNegativeSetting(entry.first, mapArgs); } } -- cgit v1.2.3 From ac14bcc1f12d2407516bcdfef57b2740df48381b Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Sat, 10 May 2014 14:54:20 +0200 Subject: small formatting, indentation and comment fixes - contains zero code changes --- src/util.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index d106b0323..cccf2df48 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -962,13 +962,15 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) void ClearDatadirCache() { std::fill(&pathCached[0], &pathCached[CChainParams::MAX_NETWORK_TYPES+1], - boost::filesystem::path()); + boost::filesystem::path()); } boost::filesystem::path GetConfigFile() { boost::filesystem::path pathConfigFile(GetArg("-conf", "bitcoin.conf")); - if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile; + if (!pathConfigFile.is_complete()) + pathConfigFile = GetDataDir(false) / pathConfigFile; + return pathConfigFile; } @@ -1028,9 +1030,9 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest) #endif /* WIN32 */ } - -// Ignores exceptions thrown by boost's create_directory if the requested directory exists. -// Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory. +// Ignores exceptions thrown by Boost's create_directory if the requested directory exists. +// Specifically handles case where path p exists, but it wasn't possible for the user to +// write to the parent directory. bool TryCreateDirectory(const boost::filesystem::path& p) { try @@ -1381,19 +1383,19 @@ bool ParseInt32(const std::string& str, int32_t *out) void SetupEnvironment() { - #ifndef WIN32 +#ifndef WIN32 try { - #if BOOST_FILESYSTEM_VERSION == 3 +#if BOOST_FILESYSTEM_VERSION == 3 boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid - #else // boost filesystem v2 +#else // boost filesystem v2 std::locale(); // Raises runtime error if current locale is invalid - #endif +#endif } catch(std::runtime_error &e) { setenv("LC_ALL", "C", 1); // Force C locale } - #endif +#endif } std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) -- cgit v1.2.3 From 97789d374c40f4f7fc8feb19c1235ca09ad2e06e Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 10 Jun 2014 16:02:29 +0200 Subject: util: Add function FormatParagraph to format paragraph to fixed-width This is to be used for the `-version` and `-help` messages. --- src/util.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index cccf2df48..3e3dabb67 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1407,3 +1407,38 @@ std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) ss << boost::posix_time::from_time_t(nTime); return ss.str(); } + +std::string FormatParagraph(const std::string in, size_t width, size_t indent) +{ + std::stringstream out; + size_t col = 0; + size_t ptr = 0; + while(ptr < in.size()) + { + // Find beginning of next word + ptr = in.find_first_not_of(' ', ptr); + if (ptr == std::string::npos) + break; + // Find end of next word + size_t endword = in.find_first_of(' ', ptr); + if (endword == std::string::npos) + endword = in.size(); + // Add newline and indentation if this wraps over the allowed width + if (col > 0) + { + if ((col + endword - ptr) > width) + { + out << '\n'; + for(size_t i=0; i Date: Tue, 27 May 2014 11:44:55 +0800 Subject: change "char pch[200000]" to "new char[200000]" --- src/util.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 30590912f..1480b2ebf 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -168,15 +168,14 @@ void RandAddSeedPerfmon() #ifdef WIN32 // Don't need this on Linux, OpenSSL automatically uses /dev/urandom // Seed with the entire set of perfmon data - unsigned char pdata[250000]; - memset(pdata, 0, sizeof(pdata)); - unsigned long nSize = sizeof(pdata); - long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, pdata, &nSize); + std::vector vData(250000,0); + unsigned long nSize = vData.size(); + long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, begin_ptr(vData), &nSize); RegCloseKey(HKEY_PERFORMANCE_DATA); if (ret == ERROR_SUCCESS) { - RAND_add(pdata, nSize, nSize/100.0); - OPENSSL_cleanse(pdata, nSize); + RAND_add(begin_ptr(vData), nSize, nSize/100.0); + OPENSSL_cleanse(begin_ptr(vData), nSize); LogPrint("rand", "RandAddSeed() %lu bytes\n", nSize); } #endif @@ -1141,15 +1140,15 @@ void ShrinkDebugFile() if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000) { // Restart the file with some of the end - char pch[200000]; - fseek(file, -sizeof(pch), SEEK_END); - int nBytes = fread(pch, 1, sizeof(pch), file); + std::vector vch(200000,0); + fseek(file, -vch.size(), SEEK_END); + int nBytes = fread(begin_ptr(vch), 1, vch.size(), file); fclose(file); file = fopen(pathLog.string().c_str(), "w"); if (file) { - fwrite(pch, 1, nBytes, file); + fwrite(begin_ptr(vch), 1, nBytes, file); fclose(file); } } -- cgit v1.2.3 From be873f64540d3c0b1227920eb466097ed738f452 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 23 Jun 2014 14:35:35 +0200 Subject: Issue warning if collecting RandSeed data failed --- src/util.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 1480b2ebf..794608957 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -176,7 +176,14 @@ void RandAddSeedPerfmon() { RAND_add(begin_ptr(vData), nSize, nSize/100.0); OPENSSL_cleanse(begin_ptr(vData), nSize); - LogPrint("rand", "RandAddSeed() %lu bytes\n", nSize); + LogPrint("rand", "%s: %lu bytes\n", __func__, nSize); + } else { + static bool warned = false; // Warn only once + if (!warned) + { + LogPrintf("%s: Warning: RegQueryValueExA(HKEY_PERFORMANCE_DATA) failed with code %i\n", __func__, ret); + warned = true; + } } #endif } -- cgit v1.2.3 From 14f888ca804386b111b07e8988753d67f507ba30 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 19 Jun 2014 15:08:37 +0200 Subject: Move network-time related functions to timedata.cpp/h The network time-offset-mangement functions from util.cpp are moved to timedata.(cpp|h). This breaks the dependency of util on netbase. --- src/util.cpp | 77 ------------------------------------------------------------ 1 file changed, 77 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 30590912f..a19c015da 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -6,7 +6,6 @@ #include "util.h" #include "chainparams.h" -#include "netbase.h" #include "sync.h" #include "ui_interface.h" #include "uint256.h" @@ -1157,13 +1156,6 @@ void ShrinkDebugFile() fclose(file); } -// -// "Never go to sea with two chronometers; take one or three." -// Our three time sources are: -// - System clock -// - Median of other nodes clocks -// - The user (asking the user to fix the system clock if the first two disagree) -// static int64_t nMockTime = 0; // For unit testing int64_t GetTime() @@ -1178,75 +1170,6 @@ void SetMockTime(int64_t nMockTimeIn) nMockTime = nMockTimeIn; } -static CCriticalSection cs_nTimeOffset; -static int64_t nTimeOffset = 0; - -int64_t GetTimeOffset() -{ - LOCK(cs_nTimeOffset); - return nTimeOffset; -} - -int64_t GetAdjustedTime() -{ - return GetTime() + GetTimeOffset(); -} - -void AddTimeData(const CNetAddr& ip, int64_t nTime) -{ - int64_t nOffsetSample = nTime - GetTime(); - - LOCK(cs_nTimeOffset); - // Ignore duplicates - static set setKnown; - if (!setKnown.insert(ip).second) - return; - - // Add data - static CMedianFilter vTimeOffsets(200,0); - vTimeOffsets.input(nOffsetSample); - LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); - if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) - { - int64_t nMedian = vTimeOffsets.median(); - std::vector vSorted = vTimeOffsets.sorted(); - // Only let other nodes change our time by so much - if (abs64(nMedian) < 70 * 60) - { - nTimeOffset = nMedian; - } - else - { - nTimeOffset = 0; - - static bool fDone; - if (!fDone) - { - // If nobody has a time different than ours but within 5 minutes of ours, give a warning - bool fMatch = false; - BOOST_FOREACH(int64_t nOffset, vSorted) - if (nOffset != 0 && abs64(nOffset) < 5 * 60) - fMatch = true; - - if (!fMatch) - { - fDone = true; - string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly."); - strMiscWarning = strMessage; - LogPrintf("*** %s\n", strMessage); - uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING); - } - } - } - if (fDebug) { - BOOST_FOREACH(int64_t n, vSorted) - LogPrintf("%+d ", n); - LogPrintf("| "); - } - LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60); - } -} - uint32_t insecure_rand_Rz = 11; uint32_t insecure_rand_Rw = 11; void seed_insecure_rand(bool fDeterministic) -- cgit v1.2.3 From 84ce18ca9339901f65d77a5821eb65f771316558 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 19 Jun 2014 15:10:04 +0200 Subject: Remove unnecessary dependencies for bitcoin-cli This commit removes all the unnecessary dependencies (key, core, netbase, sync, ...) from bitcoin-cli. To do this it shards the chain parameters into BaseParams, which contains just the RPC port and data directory (as used by utils and bitcoin-cli) and Params, with the rest. --- src/util.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index a19c015da..7a0e2cc80 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5,7 +5,7 @@ #include "util.h" -#include "chainparams.h" +#include "chainparamsbase.h" #include "sync.h" #include "ui_interface.h" #include "uint256.h" @@ -918,7 +918,7 @@ boost::filesystem::path GetDefaultDataDir() #endif } -static boost::filesystem::path pathCached[CChainParams::MAX_NETWORK_TYPES+1]; +static boost::filesystem::path pathCached[CBaseChainParams::MAX_NETWORK_TYPES+1]; static CCriticalSection csPathCached; const boost::filesystem::path &GetDataDir(bool fNetSpecific) @@ -927,8 +927,8 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) LOCK(csPathCached); - int nNet = CChainParams::MAX_NETWORK_TYPES; - if (fNetSpecific) nNet = Params().NetworkID(); + int nNet = CBaseChainParams::MAX_NETWORK_TYPES; + if (fNetSpecific) nNet = BaseParams().NetworkID(); fs::path &path = pathCached[nNet]; @@ -947,7 +947,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) path = GetDefaultDataDir(); } if (fNetSpecific) - path /= Params().DataDir(); + path /= BaseParams().DataDir(); fs::create_directories(path); @@ -956,7 +956,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) void ClearDatadirCache() { - std::fill(&pathCached[0], &pathCached[CChainParams::MAX_NETWORK_TYPES+1], + std::fill(&pathCached[0], &pathCached[CBaseChainParams::MAX_NETWORK_TYPES+1], boost::filesystem::path()); } -- cgit v1.2.3 From e10dcf27b4fb324a85b5650c7acd2ea5a52e822f Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Tue, 24 Jun 2014 14:17:43 +0200 Subject: ensure clean and consistent "namespace" usage - remove some missplaced ; - ensure end of a namespace is clearly visible - use same formatting when using namespace --- src/util.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 7a0e2cc80..7efcc577c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -77,11 +77,12 @@ // See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options // http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION namespace boost { + namespace program_options { std::string to_internal(const std::string&); } -} +} // namespace boost using namespace std; -- cgit v1.2.3 From cf04d83624e2ca66d094b6026e48bdf86693d7de Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Tue, 24 Jun 2014 14:41:26 +0200 Subject: add OpenSSL RAND_cleanup() on OpenSSL shutdown - to securely erase the memory used by the PNRG - also rework 2 comments in OpenSSL init --- src/util.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 7a0e2cc80..5c1ed23b7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -121,15 +121,17 @@ public: CRYPTO_set_locking_callback(locking_callback); #ifdef WIN32 - // Seed random number generator with screen scrape and other hardware sources + // Seed OpenSSL PRNG with current contents of the screen RAND_screen(); #endif - // Seed random number generator with performance counter + // Seed OpenSSL PRNG with performance counter RandAddSeed(); } ~CInit() { + // Securely erase the memory used by the PRNG + RAND_cleanup(); // Shutdown OpenSSL library multithreading support CRYPTO_set_locking_callback(NULL); for (int i = 0; i < CRYPTO_num_locks(); i++) -- cgit v1.2.3 From 8ae973c00cfb02161bb2c2a6c839e510cd409278 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 24 Jun 2014 15:27:37 +0200 Subject: Allocate more space if necessary in RandSeedAddPerfMon Currently we use a fixed buffer of 250000 bytes to request HKEY_PERFORMANCE_DATA. In many cases this is not enough, causing the entropy collection to be skipped. Use a loop that grows the buffer as specified in the RegQueryValueEx documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724911%28v=vs.85%29.aspx (as the size of the performance data can differ for every call, the normal solution of requesting the size then allocating that can't work) --- src/util.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 794608957..a96963689 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -169,8 +169,17 @@ void RandAddSeedPerfmon() // Don't need this on Linux, OpenSSL automatically uses /dev/urandom // Seed with the entire set of perfmon data std::vector vData(250000,0); - unsigned long nSize = vData.size(); - long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, begin_ptr(vData), &nSize); + long ret = 0; + unsigned long nSize = 0; + const size_t nMaxSize = 10000000; // Bail out at more than 10MB of performance data + while (true) + { + nSize = vData.size(); + ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, begin_ptr(vData), &nSize); + if (ret != ERROR_MORE_DATA || vData.size() >= nMaxSize) + break; + vData.resize(std::max((vData.size()*3)/2, nMaxSize)); // Grow size of buffer exponentially + } RegCloseKey(HKEY_PERFORMANCE_DATA); if (ret == ERROR_SUCCESS) { -- cgit v1.2.3 From de79aaa7a9ad07664461ee8735299aa68c630969 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 28 Jun 2014 17:35:22 +0200 Subject: Move non-trivial uint256.h methods to uint256.cpp --- src/util.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 9e4b2b787..e67c0dfd8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -419,6 +419,11 @@ const signed char p_util_hexdigit[256] = -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, }; +signed char HexDigit(char c) +{ + return p_util_hexdigit[(unsigned char)c]; +} + bool IsHex(const string& str) { BOOST_FOREACH(char c, str) -- cgit v1.2.3 From 2e36866fecb7420cd73047a7aa762a6e5e225695 Mon Sep 17 00:00:00 2001 From: R E Broadley Date: Wed, 26 Feb 2014 17:55:04 -0800 Subject: Show nodeid instead of addresses (for anonymity) unless otherwise requested. --- src/util.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 5a8f85ade..081484c37 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -95,6 +95,7 @@ bool fDaemon = false; bool fServer = false; string strMiscWarning; bool fLogTimestamps = false; +bool fLogIPs = false; volatile bool fReopenDebugLog = false; CClientUIInterface uiInterface; -- cgit v1.2.3 From 73ac7abd08a70adf22e24d0f5f7631e7f8b7c5bb Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 3 Jul 2014 07:45:16 +0200 Subject: Move ui_interface to bitcoin_server.a There is no need for it in the utility libraries or tools. Put it in init.cpp, and in the tests separately (as they can't link init). --- src/util.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 081484c37..9adbbdec4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -7,7 +7,6 @@ #include "chainparamsbase.h" #include "sync.h" -#include "ui_interface.h" #include "uint256.h" #include "version.h" @@ -97,7 +96,6 @@ string strMiscWarning; bool fLogTimestamps = false; bool fLogIPs = false; volatile bool fReopenDebugLog = false; -CClientUIInterface uiInterface; // Init OpenSSL library multithreading support static CCriticalSection** ppmutexOpenSSL; -- cgit v1.2.3