test: Remove tests violating hardened std::span
What changed, and why it matters
This is a test-only change. It removes unit tests that created a std::span from a null pointer with a non-zero length, which is undefined behavior and now trapped by hardened std::span implementations. The production code is not changed, and no vulnerability in live Bitcoin Core is introduced or fixed here.
No action required for production deployments. Reviewers may verify that the kernel constructors still validate empty or invalid input through the remaining tests (empty_data, invalid_data).
Security signals we found
Removal of undefined-behavior test inputs (null pointer + non-zero span length)
Hardened std::span compatibility cleanup in test code
No production code changes
Evidence from the diff
The commit modifies src/test/kernel/test_kernel.cpp only. It deletes three BOOST_CHECK_THROW assertions that constructed std::span
Changed components
src/test/kernel/test_kernel.cppInspect captured patch +3 / −3
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
index 75c9e466..474e0d4a 100644
--- a/src/test/kernel/test_kernel.cpp
+++ b/src/test/kernel/test_kernel.cpp
@@ -398,7 +398,6 @@ BOOST_AUTO_TEST_CASE(btck_transaction_tests)
BOOST_CHECK_THROW(Transaction{invalid_data}, std::runtime_error);
auto empty_data = hex_string_to_byte_vec("");
BOOST_CHECK_THROW(Transaction{empty_data}, std::runtime_error);
- BOOST_CHECK_THROW(Transaction{std::span<std::byte>(static_cast<std::byte*>(nullptr), 2)}, std::runtime_error);
BOOST_CHECK_EQUAL(tx.CountOutputs(), 2);
BOOST_CHECK_EQUAL(tx.CountInputs(), 1);
@@ -475,7 +474,9 @@ BOOST_AUTO_TEST_CASE(btck_script_pubkey)
ScriptPubkey script2{script_data_2};
CheckHandle(script, script2);
- BOOST_CHECK_THROW(ScriptPubkey{std::span<std::byte>(static_cast<std::byte*>(nullptr), 2)}, std::runtime_error);
+ std::span<std::byte> empty_data{};
+ ScriptPubkey empty_script{empty_data};
+ CheckHandle(script, empty_script);
}
BOOST_AUTO_TEST_CASE(btck_transaction_output)
@@ -592,7 +593,6 @@ BOOST_AUTO_TEST_CASE(btck_block)
BOOST_CHECK_THROW(Block{invalid_data}, std::runtime_error);
auto empty_data = hex_string_to_byte_vec("");
BOOST_CHECK_THROW(Block{empty_data}, std::runtime_error);
- BOOST_CHECK_THROW(Block{std::span<std::byte>(static_cast<std::byte*>(nullptr), 2)}, std::runtime_error);
}
Context create_context(std::shared_ptr<TestKernelNotifications> notifications, ChainType chain_type, std::shared_ptr<TestValidationInterface> validation_interface = nullptr)
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.