mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-04 10:59:08 +02: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:
@@ -24,6 +24,7 @@
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
class arith_uint256;
|
||||
class CFeeRate;
|
||||
class Chainstate;
|
||||
class FastRandomContext;
|
||||
@@ -236,7 +237,9 @@ std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::
|
||||
|
||||
CBlock getBlock13b8a();
|
||||
|
||||
// define an implicit conversion here so that uint256 may be used directly in BOOST_CHECK_*
|
||||
// Make types usable in BOOST_CHECK_*
|
||||
std::ostream& operator<<(std::ostream& os, const arith_uint256& num);
|
||||
std::ostream& operator<<(std::ostream& os, const uint160& num);
|
||||
std::ostream& operator<<(std::ostream& os, const uint256& num);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user