mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
Merge #19508: Work around memory-aliasing in descriptor ParsePubkey
fa2ae0ac8d
span: Add Span::empty() and use it in script/descriptor (MarcoFalke)fa8a992589
Work around memory-aliasing in descriptor ParsePubkey (MarcoFalke) Pull request description: While this is not undefined behaviour, the memory aliasing trick is confusing when reading the code. Having `a.size()==0` and then access `a[0]` works in this particular case, but should probably be avoided to harden the code for the future. ACKs for top commit: theStack: re-ACKfa2ae0ac8d
elichai: ACKfa2ae0ac8d
jonatack: ACKfa2ae0ac8d
Tree-SHA512: 0ec7b09eef45504973a195923cdf1aa8522117c8e2f69b453e5ce9aa8a7e327c71138518022c32d05133dc99cb861101ed0f60fa891814ee3e9dab3a6fa61a84
This commit is contained in:
commit
31d2b4098a
2 changed files with 5 additions and 3 deletions
|
@ -825,8 +825,9 @@ std::unique_ptr<PubkeyProvider> ParsePubkey(uint32_t key_exp_index, const Span<c
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (origin_split.size() == 1) return ParsePubkeyInner(key_exp_index, origin_split[0], permit_uncompressed, out, error);
|
if (origin_split.size() == 1) return ParsePubkeyInner(key_exp_index, origin_split[0], permit_uncompressed, out, error);
|
||||||
if (origin_split[0].size() < 1 || origin_split[0][0] != '[') {
|
if (origin_split[0].empty() || origin_split[0][0] != '[') {
|
||||||
error = strprintf("Key origin start '[ character expected but not found, got '%c' instead", origin_split[0][0]);
|
error = strprintf("Key origin start '[ character expected but not found, got '%c' instead",
|
||||||
|
origin_split[0].empty() ? /** empty, implies split char */ ']' : origin_split[0][0]);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto slash_split = Split(origin_split[0].subspan(1), '/');
|
auto slash_split = Split(origin_split[0].subspan(1), '/');
|
||||||
|
@ -896,7 +897,7 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t key_exp_index, Span<const c
|
||||||
providers.emplace_back(std::move(pk));
|
providers.emplace_back(std::move(pk));
|
||||||
key_exp_index++;
|
key_exp_index++;
|
||||||
}
|
}
|
||||||
if (providers.size() < 1 || providers.size() > 16) {
|
if (providers.empty() || providers.size() > 16) {
|
||||||
error = strprintf("Cannot have %u keys in multisig; must have between 1 and 16 keys, inclusive", providers.size());
|
error = strprintf("Cannot have %u keys in multisig; must have between 1 and 16 keys, inclusive", providers.size());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else if (thres < 1) {
|
} else if (thres < 1) {
|
||||||
|
|
|
@ -151,6 +151,7 @@ public:
|
||||||
return m_data[m_size - 1];
|
return m_data[m_size - 1];
|
||||||
}
|
}
|
||||||
constexpr std::size_t size() const noexcept { return m_size; }
|
constexpr std::size_t size() const noexcept { return m_size; }
|
||||||
|
constexpr bool empty() const noexcept { return size() == 0; }
|
||||||
CONSTEXPR_IF_NOT_DEBUG C& operator[](std::size_t pos) const noexcept
|
CONSTEXPR_IF_NOT_DEBUG C& operator[](std::size_t pos) const noexcept
|
||||||
{
|
{
|
||||||
ASSERT_IF_DEBUG(size() > pos);
|
ASSERT_IF_DEBUG(size() > pos);
|
||||||
|
|
Loading…
Add table
Reference in a new issue