mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
Merge bitcoin/bitcoin#30436: fix: Make TxidFromString() respect string_view length
09ce3501fafix: Make TxidFromString() respect string_view length (Hodlinator)01e314ce0arefactor: Change base_blob::SetHex() to take std::string_view (Hodlinator)2f5577dc2etest: uint256 - Garbage suffixes and zero padding (Hodlinator)f11f816800refactor: Make uint256_tests no longer use deprecated BOOST_CHECK() (Hodlinator)f0eeee2dc1test: Add test for TxidFromString() behavior (Ryan Ofsky) Pull request description: ### Problem Prior to this, `TxidFromString()` was passing `string_view::data()` into `uint256S()` which meant it would only receive the a naked `char*` pointer and potentially scan past the `string_view::length()` until it found a null terminator (or some other non-hex character). Appears to have been a fully dormant bug as callers were either passing a string literal or `std::string` directly to `TxidFromFromString()`, meaning a null terminator always existed at `pointer[length()]`. Bug existed since original merge of `TxidFromString()`. ### Solution Make `uint256S()` (and `base_blob::SetHex()`) take and operate on `std::string_view` instead of `const char*` and have `TxidFromString()` pass that in. (PR was prompted by comment in https://github.com/bitcoin/bitcoin/pull/30377#issuecomment-2208857200 (referring to https://github.com/bitcoin/bitcoin/pull/28922#discussion_r1404437378)). ACKs for top commit: maflcko: re-ACK09ce3501fa🕓 paplorinc: ACK09ce3501faryanofsky: Code review ACK09ce3501fa. I think the current code changes are about as small as you could make to fix the bug without introducing a string copy, and the surrounding test improvements are all very nice and welcome. Tree-SHA512: c2c10551785fb6688d1e2492ba42a8eee4c19abbe8461bb0774d56a70c23cd6b0718d2641632890bee880c06202dee148126447dd2264eaed4f5fee7e1bcb581
This commit is contained in:
@@ -79,6 +79,18 @@ const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
||||
/** Random context to get unique temp data dirs. Separate from g_insecure_rand_ctx, which can be seeded from a const env var */
|
||||
static FastRandomContext g_insecure_rand_ctx_temp_path;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const arith_uint256& num)
|
||||
{
|
||||
os << ArithToUint256(num).ToString();
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const uint160& num)
|
||||
{
|
||||
os << num.ToString();
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const uint256& num)
|
||||
{
|
||||
os << num.ToString();
|
||||
|
||||
Reference in New Issue
Block a user