mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 11:44:14 +01:00
fix: Make TxidFromString() respect string_view length
Prior to this, passing string_view::data() into uint256S() meant the latter 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 null terminator always existed at pointer[length()]. Bug existed since original merge of TxidFromString(), discussed in https://github.com/bitcoin/bitcoin/pull/28922#discussion_r1404437378.
This commit is contained in:
@@ -1030,10 +1030,10 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_TxidFromString)
|
||||
{
|
||||
// TxidFromString currently ignores string_view length and reads the whole
|
||||
// string, not the specified substring.
|
||||
// Make sure TxidFromString respects string_view length and stops reading at
|
||||
// end of the substring.
|
||||
BOOST_CHECK_EQUAL(TxidFromString(std::string_view("ABCD1234", 4)).ToString(),
|
||||
"00000000000000000000000000000000000000000000000000000000abcd1234");
|
||||
"000000000000000000000000000000000000000000000000000000000000abcd");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user