aboutsummaryrefslogtreecommitdiff
path: root/src/util
AgeCommit message (Collapse)Author
2022-04-13Merge bitcoin/bitcoin#24355: util, refactor: Add UNIQUE_NAME helper macrolaanwj
1633f5ec8846408182cceb60dc88f022635f4002 util, refactor: Add UNIQUE_NAME helper macro (Hennadii Stepanov) Pull request description: This PR replaces repetitive code with a helper macro. ACKs for top commit: laanwj: Tested ACK 1633f5ec8846408182cceb60dc88f022635f4002 Tree-SHA512: 5f04e472c5f3184c0a9df75395377c6744bfb2cd8f95f8427c1c5e20daa7d6a9b29e45424b88391fc6326d365907a750ab50fda534b49d1df80dccf0e18467a4
2022-04-05Remove gui-only syscallsMarcoFalke
* Revert "util: Add inotify_rm_watch to syscall sandbox (AllowFileSystem)" This reverts commit f05a4cdf5a0363e1c12f00c034afb60e7ea0c775. * Revert "util: add linkat to syscall sandbox (AllowFileSystem)" This reverts commit 9809db3577f0fa618bea42635b1581e628a30395.
2022-04-05init: Disable syscall sandbox in the bitcoin-qt processMarcoFalke
2022-04-04Merge bitcoin/bitcoin#24729: util/check: avoid unused parameter warningsMarcoFalke
0add4dbadbc972933b0c99813a155a4ed4852975 util/check: avoid unused parameter warnings (Anthony Towns) Pull request description: Add `[[maybe_unused]]` annotations to avoid warnings from gcc 9.4 and earlier which don't analyse `if constexpr` properly. ACKs for top commit: MarcoFalke: review ACK 0add4dbadbc972933b0c99813a155a4ed4852975 jonatack: ACK 0add4dbadbc972933b0c99813a155a4ed4852975 review and debug build on clang 15 shaavan: ACK 0add4dbadbc972933b0c99813a155a4ed4852975 Tree-SHA512: 3ba490d74d91692c1d22b927da43a130c92cd6a20ed168573e4fbe1f4675fef7e05ebf0b11f2bbd15da3c606fea1f8e6403cfca347009b8b6acc1e77bbee9963
2022-04-01refactor: add missing std:: includes to threadnames.cppfanquake
2022-04-01doc: remove incorrect mention of PR_GET_NAMEfanquake
By removing the whole comment. These #include // For comments are near impossible to maintain, pollute diffs, and generally don't add a lot of value.
2022-04-01util/check: avoid unused parameter warningsAnthony Towns
2022-03-31Merge bitcoin/bitcoin#24714: util/check: Don't use a lambda for Assert/AssumeMarcoFalke
2ef47ba6c57a12840499a13908ab61aefca6cb55 util/check: stop using lambda for Assert/Assume (Anthony Towns) 7c9fe25c16d48b53a61fa2f6ff77eaf8820cb1f6 wallet: move Assert() check into constructor (Anthony Towns) Pull request description: Using a lambda creates a couple of odd namespacing issues, in particular making clang's thread safety analysis less helpful, and confusing gcc when calling member functions. Fix this by not using a lambda. Fixes #21596 Fixes #24654 ACKs for top commit: MarcoFalke: ACK 2ef47ba6c57a12840499a13908ab61aefca6cb55 🚢 jonatack: Tested re-ACK 2ef47ba6c57a12840499a13908ab61aefca6cb55 Tree-SHA512: 4bdbf3215f3d14472df0552362c5eebe8b7eea2d0928a8a41109edd4e0c5f95de6f8220eb2fee8506874e352c003907faf5ef344174795939306a618157b1bae
2022-03-30util/check: stop using lambda for Assert/AssumeAnthony Towns
2022-03-30Merge bitcoin/bitcoin#24690: util: Add inotify_rm_watch to syscall sandbox ↵fanquake
(AllowFileSystem) f05a4cdf5a0363e1c12f00c034afb60e7ea0c775 util: Add inotify_rm_watch to syscall sandbox (AllowFileSystem) (Hennadii Stepanov) Pull request description: This PR fixes the current master (3297f5c11c72dd83479ff8335e047555e3f8cb3b) when running `bitcoin-qt` on Ubuntu 22.04 and quitting: ``` $ ./src/qt/bitcoin-qt -signet -sandbox=log-and-abort Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. ERROR: The syscall "inotify_rm_watch" (syscall number 255) is not allowed by the syscall sandbox in thread "main". Please report. terminate called without an active exception Aborted (core dumped) ``` Also see https://github.com/bitcoin/bitcoin/pull/24659#discussion_r835747166 ACKs for top commit: fanquake: ACK f05a4cdf5a0363e1c12f00c034afb60e7ea0c775 - checked that qt is using this in it's filesystem watcher code. Tree-SHA512: 9c7920a25422cd3a040bc1cbc487c12c3dc2b91358c3757f1030d6a1ff12c18c688a8e5b7466f683da88a5e4f5f15d442975660022d706e47021253c24c58f4a
2022-03-29Merge bitcoin/bitcoin#24523: build: Fix Boost.Process test for Boost 1.78laanwj
532c64a7264dd3c7329e8839547837c57da7dbe8 build: Fix Boost.Process test for Boost 1.78 (Hennadii Stepanov) Pull request description: Rebased #24415 with Luke's suggestion. Fixes #24413. ACKs for top commit: hebasto: ACK 532c64a7264dd3c7329e8839547837c57da7dbe8, tested on Mac mini (M1, 2020) + macOS Monterey 12.3 (21E230). Tree-SHA512: 74f779695f6bbc45a2b7341a1402f747cc0d433d74825c7196cb9f156db0c0299895365f01665bd0bff12a8ebb5ea33a29b9a52f5eac0007ec35d1dca6544705
2022-03-28util: Add inotify_rm_watch to syscall sandbox (AllowFileSystem)Hennadii Stepanov
2022-03-24util: add linkat to syscall sandbox (AllowFileSystem)fanquake
2022-03-21build: Fix Boost.Process test for Boost 1.78Hennadii Stepanov
2022-03-10Merge bitcoin/bitcoin#24371: util: Fix `ReadBinaryFile` reading beyond maxsizeMarcoFalke
a84650ebd5ac2cbb49f14eb7c98736a3f8215bf1 util: Fix ReadBinaryFile reading beyond maxsize (klementtan) Pull request description: Currently `ReadBinaryFile` will read beyond `maxsize` if `maxsize` is not a multiple of `128` (size of buffer) This is due to `fread` being called with `count = 128` instead of `count = min(128, maxsize - retval.size()` at every iteration The following unit test will fail: ```cpp BOOST_AUTO_TEST_CASE(util_ReadWriteFile) { fs::path tmpfolder = m_args.GetDataDirBase(); fs::path tmpfile = tmpfolder / "read_binary.dat"; std::string expected_text(300,'c'); { std::ofstream file{tmpfile}; file << expected_text; } { // read half the contents in file auto [valid, text] = ReadBinaryFile(tmpfile, expected_text.size() / 2); BOOST_CHECK_EQUAL(text.size(), 150); } } ``` Error: ``` test/util_tests.cpp:2593: error: in "util_tests/util_ReadWriteFile": check text.size() == 150 has failed [256 != 150] ``` ACKs for top commit: laanwj: Code review ACK a84650ebd5ac2cbb49f14eb7c98736a3f8215bf1 theStack: Code-review ACK a84650ebd5ac2cbb49f14eb7c98736a3f8215bf1 Tree-SHA512: 752eebe58bc2102dec199b6775f8c3304d899f0ce36d6a022a58e27b076ba945ccd572858b19137b769effd8c6de73a9277f641be24dfb17657fb7173ea0eda0
2022-03-07qt: Avoid crash on startup if int specified in settings.jsonRyan Ofsky
Fix GUI startup crash reported by Rspigler in https://github.com/bitcoin/bitcoin/issues/24457 that happens if settings.json contains an integer value for any of the configuration options which GUI settings can currently clash with (-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen, -server, -proxy, -proxy, -onion, -onion, -lang, and -prune). Fix is a one-line change in ArgsManager::GetArg.
2022-03-02util, refactor: Use GetPathArg to read "-settings" valueRyan Ofsky
Take advantage of GetPathArg to simplify code slightly.
2022-03-02util: Add GetPathArg default path argumentRyan Ofsky
Let GetPathArg method be used more places for path arguments that have default values, like "-settings" and BITCOIN_SETTINGS_FILENAME in the next commit. Also: - Fix negated argument handling. Return path{} not path{"0"} when path argument is negated. - Add new tests for default and negated cases - Move GetPathArg() method declaration next to GetArg() declarations. The two methods are close substitutes for each other, so this should help keep them consistent and make them more discoverable.
2022-02-22refactor: shift CopyrightHolders() and LicenseInfo() to clientversion.cppfanquake
2022-02-21util: Add SaturatingAdd helperMarcoFalke
2022-02-21Merge bitcoin/bitcoin#24231: streams: Fix read-past-the-end and integer ↵MarcoFalke
overflows fa1b89a6bdbab50bdb0504782afd4bb3375d1b57 scripted-diff: Rename nReadPos to m_read_pos in streams.h (MarcoFalke) fa56c79df91e5d87533af38b64f4f4148a48a276 Make CDataStream work properly on 64-bit systems (MarcoFalke) fab02f799194c75af7def3a2ab45c443b75de230 streams: Fix read-past-the-end and integer overflows (MarcoFalke) Pull request description: This is a follow-up to commit e26b62093ae21e89ed7d36a24a6b863f38ec631d with the following fixes: * Fix unsigned integer overflow in `ignore()`, when `nReadPos` wraps. * Fix unsigned integer overflow in `read()`, when `nReadPos` wraps. * Fix read-past-the-end in `read()`, when `nReadPos` wraps. This shouldn't be remote-exploitable, because it requires a stream of more than 1GB of size. However, it might be exploitable if the attacker controls the datadir (I haven't checked). A unit test for the overflow in `ignore()` looks like following. It is left as an excercise to the reader to replace `foo.ignore(7)` with the appropriate call to `read()` to reproduce the overflow and read-error in `read()`. ```diff diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 922fd8e513..ec6ea93919 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -534,6 +534,20 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization) } catch (const std::ios_base::failure&) { } + CDataStream foo{0, 0}; + auto size{std::numeric_limits<uint32_t>::max()}; + foo.resize(size); + BOOST_CHECK_EQUAL(foo.size(), size); + foo.ignore(std::numeric_limits<int32_t>::max()); + size -= std::numeric_limits<int32_t>::max(); + BOOST_CHECK_EQUAL(foo.size(), size); + foo.ignore(std::numeric_limits<int32_t>::max()); + size -= std::numeric_limits<int32_t>::max(); + BOOST_CHECK_EQUAL(foo.size(), size); + BOOST_CHECK_EQUAL(foo.size(), 1); + foo.ignore(7); // Should overflow, as the size is only 1 + BOOST_CHECK_EQUAL(foo.size(), uint32_t(1 - 7)); + // Very large scriptPubKey (3*10^9 bytes) past the end of the stream CDataStream tmp(SER_DISK, CLIENT_VERSION); uint64_t x = 3000000000ULL; ``` ACKs for top commit: klementtan: Code Review ACK fa1b89a6bdbab50bdb0504782afd4bb3375d1b57: Tree-SHA512: 67f0a1baafe88eaf1dc844ac55b638d5cf168a18c945e3bf7a2cb03c9a5976674a8e3af2487d8a2c3eae21e5c0e7a519c8b16ee7f104934442e2769d100660e9
2022-02-19util: Fix ReadBinaryFile reading beyond maxsizeklementtan
2022-02-17util: Add missing rseq to syscall sandboxlaanwj
Fixes #24368.
2022-02-17Merge bitcoin/bitcoin#24331: util: Revert back `MoveFileExW` call for MinGW-w64laanwj
dc01cbc538765f64326bca30952c83e3862d0d54 test: Add fs_tests/rename unit test (Hennadii Stepanov) d4999d40b9bd04dc20111aaaa6ed2d3db1a5caf9 util: Revert back MoveFileExW call for MinGW-w64 (Hennadii Stepanov) Pull request description: Unfortunately, bitcoin/bitcoin#24308 introduced a [regression](https://github.com/bitcoin/bitcoin/pull/24308#issuecomment-1037259386) for mingw builds. The root of the problem is a broken implementation of [`std::filesystem::rename`](https://en.cppreference.com/w/cpp/filesystem/rename). In particular, the expected behavior > If `old_p` is a non-directory file, then `new_p` must be ... existing non-directory file: `new_p` _is first deleted_... fails with the "File exists" error. This PR reverts back the `MoveFileExW` call, and adds the [suggested](https://github.com/bitcoin/bitcoin/pull/24308#pullrequestreview-878832906) unit test. ACKs for top commit: vasild: ACK dc01cbc538765f64326bca30952c83e3862d0d54 Tree-SHA512: c8e5a98844cfa32bec0ad67a1aaa58fe2efd0c5474d3e83490211985b110f83245758a742dcaa0a933a192ab66a7f11807e0c53ae69260b7dd02fc99f6d03849
2022-02-16util, refactor: Add UNIQUE_NAME helper macroHennadii Stepanov
This change replaces repetitive code with a helper macro.
2022-02-14util: Add missing unlinkat to syscall sandboxMarcoFalke
2022-02-14util: Revert back MoveFileExW call for MinGW-w64Hennadii Stepanov
2022-02-10util: use stronger-guarantee rename methodVasil Dimov
Use std::filesystem::rename() instead of std::rename(). We rely on the destination to be overwritten if it exists, but std::rename()'s behavior is implementation-defined in this case.
2022-02-10Merge bitcoin/bitcoin#24297: Fix unintended unsigned integer overflow in ↵fanquake
strencodings fac9fe5d051264fcd16e8e36d30f28c05c999837 Fix unintended unsigned integer overflow in strencodings (MarcoFalke) Pull request description: This fixes two issues for strings that start with a colon and only have one colon: * `fMultiColon` is incorrectly set to `true` * There is an unsigned integer overflow `colon - 1` (`0 - 1`) Neither issue matters, as the result is discarded. Though, it makes sense to still fix the issue for clarity and to avoid sanitizer issues in the function. ACKs for top commit: laanwj: Code review ACK fac9fe5d051264fcd16e8e36d30f28c05c999837 shaavan: Code Review ACK fac9fe5d051264fcd16e8e36d30f28c05c999837 Tree-SHA512: e71c21a0b617abf241e561ce6b90b963e2d5e2f77bd9547ce47209a1a94b454384391f86ef5d35fedd4f4df19add3896bb3d61fed396ebba8e864e3eeb75ed59
2022-02-10Merge bitcoin/bitcoin#24298: fuzz: Avoid unsigned integer overflow in ↵fanquake
FormatParagraph fa2f7d005932bff9b7d27744ae517b9e7910df8d fuzz: Avoid unsigned integer overflow in FormatParagraph (MarcoFalke) Pull request description: `FormatParagraph` is only ever called with compile time constant arguments, so I don't see the need for fuzzing it. Though, keep it for now, but avoid the unsigned integer overflow with this patch. ACKs for top commit: laanwj: Code review ACK fa2f7d005932bff9b7d27744ae517b9e7910df8d Tree-SHA512: 01fc64a9ef73c183921ca1b0cd8db9514c0a242e3acf215a3393f383ae129e01625ebb16eaf9cb86370eda62d0145c3dcf8f62e40edf5958abc1f777c5687280
2022-02-09util: Drop no longer needed StripRedundantLastElementsOfPath() functionHennadii Stepanov
2022-02-09Use ArgsManager::GetPathArg() for "-blocksdir" optionHennadii Stepanov
2022-02-09Use ArgsManager::GetPathArg() for "-datadir" optionHennadii Stepanov
2022-02-09util: Add ArgsManager::GetPathArg() functionHennadii Stepanov
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2022-02-09streams: Fix read-past-the-end and integer overflowsMarcoFalke
2022-02-09fuzz: Avoid unsigned integer overflow in FormatParagraphMarcoFalke
2022-02-09Fix unintended unsigned integer overflow in strencodingsMarcoFalke
2022-02-08Merge bitcoin/bitcoin#24266: util: Avoid buggy ↵MarcoFalke
std::filesystem:::create_directories() call b9c113af754540341d9529532fbadb7525168102 util: Avoid buggy std::filesystem:::create_directories() call (Hennadii Stepanov) Pull request description: Compiled with some libstdc++ versions (e.g., on Ubuntu 20.04) [`std::filesystem:::create_directories()`](https://en.cppreference.com/w/cpp/filesystem/create_directory) call [fails](https://github.com/bitcoin/bitcoin/issues/24257#issue-1123753243) to handle symbol links properly. No behavior change in comparison to the [pre-20744](https://github.com/bitcoin/bitcoin/commit/c194293883fbb656779102309b2cb3e60889feff) master branch. Fixes bitcoin/bitcoin#24257. ACKs for top commit: ryanofsky: Code review ACK b9c113af754540341d9529532fbadb7525168102. Nice simplification and fix MarcoFalke: review ACK b9c113af754540341d9529532fbadb7525168102 🐬 Tree-SHA512: 79d940cfc1f68d9b0548fb2ab005e90850b54ac0fb3bb2940afd632d56288d92687579a3176bac3fd0ea3d2dae71e26444f8f7bdb87862414c12866ae5e857c4
2022-02-05util: Avoid buggy std::filesystem:::create_directories() callHennadii Stepanov
Compiled with some libstdc++ versions (e.g., on Ubuntu 20.04) std::filesystem:::create_directories() call fails to handle symbol links properly.
2022-02-04Re-enable util_datadir check disabled in #20744Ryan Ofsky
This should also fix an assert error if a -datadir with a trailing slash is used on windows. This appears to be a real error and regression introduced with #20744. On windows (or at least wine), fs calls that actuallly access the filesystem like fs::equivalent or fs::exists seem to treat directory paths with trailing slashes as not existing, so it's necessary to normalize these paths before using them. This fix adds a path::lexically_normal() call to the failing assert so it passes.
2022-02-03refactor: replace boost::filesystem with std::filesystemKiminuo
Warning: Replacing fs::system_complete calls with fs::absolute calls in this commit may cause minor changes in behaviour because fs::absolute no longer strips trailing slashes; however these changes are believed to be safe. Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-01-26fs: consistently use fsbridge for {i,o}fstreamfanquake
Part of #20744, but this can be done now, and will simplify the diff.
2022-01-20Merge bitcoin/bitcoin#24065: build: explicitly disable support for external ↵fanquake
signing on Windows e2ab9f83f8655bf09ea392beeee36b2bbe29769b build: disable external signer on Windows (fanquake) Pull request description: This change explicitly disables support for external signing when targeting Windows and OpenBSD. The driver for this is that Boost Process uses boost::filesystem internally, when targeting Windows, which gets in the way of removing our usage of it (#20744). While we could adjust #20744 to still link against the Boost libs when building for Windows, that would be disappointing, as we wouldn't have cleanly removed the Boost usage we're trying too (including the build infrastructure), and, we'd be in a position where we would be building releases differently depending on the platform, which is something I want to avoid. After discussion with Sjors, Achow and Hebasto, this seemed like a reasonable step to move #20744 forward (as-is). Note that support for external signing ([while already being experimental](https://github.com/bitcoin/bitcoin/blob/master/doc/external-signer.md#example-usage)), could be considered even more experimental on Windows. Also, oddly, we have external-signing [explicitly disabled in our Windows (cross-compile) CI](https://github.com/bitcoin/bitcoin/blob/807169e10b4a18324356ed6ee4d69587b96a7c70/ci/test/00_setup_env_win64.sh#L16), it's not clear why this is the case, as, if it's a feature being built into releases, it should be being built and tested in the CI which is most-like the release process. There is an [issue open upstream](https://github.com/boostorg/process/issues/207), in regards to migrating Boost Process to std::filesystem, or having an option to use it. However there hasn't been much discussion since it was opened ~9 months ago. There is another related issue here: https://github.com/klemens-morgenstern/boost-process/issues/164. Resolves #24036. ACKs for top commit: Sjors: utACK e2ab9f8 achow101: ACK e2ab9f83f8655bf09ea392beeee36b2bbe29769b kallewoof: utACK e2ab9f83f8655bf09ea392beeee36b2bbe29769b hebasto: ACK e2ab9f83f8655bf09ea392beeee36b2bbe29769b, tested on Linux Mint 20.2 (x86_64). Tree-SHA512: 36fcfc0e1a008a8271dc76b8e12e93d3e1d1e528bf668e95a559e9f6fd7d5f031bd7a6a6bc8b9fa9d057b2cd56f9ec8838c7f74e87899bf9a6aeb787afbd112c
2022-01-18util: Fix mis-swapped `prettyIndent` and `indentLevel` argumentsHennadii Stepanov
2022-01-15build: disable external signer on Windowsfanquake
2022-01-11util: Restore GetIntArg saturating behaviorJames O'Beirne
The new locale-independent atoi64 method introduced in #20452 parses large integer values higher than maximum representable value as 0 instead of the maximum value, which breaks backwards compatibility. This commit restores compatibility and adds test coverage for this case in terms of the related GetIntArg and strtoll functions. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2022-01-07Add FastRange32 function and use it throughout the codebasePieter Wuille
2022-01-06scripted-diff: rename MapIntoRange to FastRange64Pieter Wuille
-BEGIN VERIFY SCRIPT- sed -i -e 's/MapIntoRange/FastRange64/' src/blockfilter.cpp src/test/fuzz/golomb_rice.cpp src/util/fastrange.h -END VERIFY SCRIPT-
2022-01-06[moveonly] Move MapIntoRange() to separate util/fastrange.hPieter Wuille
2022-01-06Merge bitcoin/bitcoin#23760: util: move MapIntoRange() for reuse in fuzz testsMarcoFalke
df2307cdc3d08233d17beb9a50c144baaef1f44e util: move MapIntoRange() for reuse in fuzz tests (fanquake) Pull request description: ACKs for top commit: shaavan: ACK df2307cdc3d08233d17beb9a50c144baaef1f44e Tree-SHA512: 31bf18f50a82e442ff025d6be0db5666b463a1fc16ec6b2112c77bb815515d27f8a537a0c9934c7daa3f4d526b47e8d6333f75a13b271e6efa550f8e71504b0a