fuzz: Reject too large descriptor leaf sizes in scriptpubkeyman target
This commit is contained in:
3 files changed
+29
No files matched your search
@@ -143,3 +143,23 @@ bool HasTooManyWrappers(std::span<const uint8_t> buff, const int max_wrappers)
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HasTooLargeLeafSize(std::span<const uint8_t> buff, const uint32_t max_leaf_size)
|
||||||
|
{
|
||||||
|
uint32_t leaf_len{0};
|
||||||
|
for (auto c : buff) {
|
||||||
|
if (c == '(' || c == ')' || c == ',' || c == '{' || c == '}') {
|
||||||
|
// Possibly start a fresh leaf, or a fresh function name (with
|
||||||
|
// wrappers), or terminate a prior leaf.
|
||||||
|
leaf_len = 0;
|
||||||
|
} else {
|
||||||
|
// Just treat everything else as a leaf. This will also reject long
|
||||||
|
// function names, but this should be fine if the max_leaf_size is
|
||||||
|
// set large enough.
|
||||||
|
if (++leaf_len > max_leaf_size) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -76,4 +76,12 @@ constexpr int MAX_WRAPPERS{100};
|
|||||||
*/
|
*/
|
||||||
bool HasTooManyWrappers(std::span<const uint8_t> buff, int max_wrappers = MAX_WRAPPERS);
|
bool HasTooManyWrappers(std::span<const uint8_t> buff, int max_wrappers = MAX_WRAPPERS);
|
||||||
|
|
||||||
|
/// Default maximum leaf size. This should be large enough to cover an extended
|
||||||
|
/// key, including paths "/", inside and outside of "[]".
|
||||||
|
constexpr uint32_t MAX_LEAF_SIZE{200};
|
||||||
|
|
||||||
|
/// Whether the expanded buffer (after calling GetDescriptor() in
|
||||||
|
/// MockedDescriptorConverter) has a leaf size too large.
|
||||||
|
bool HasTooLargeLeafSize(std::span<const uint8_t> buff, uint32_t max_leaf_size = MAX_LEAF_SIZE);
|
||||||
|
|
||||||
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
|
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
|
||||||
@@ -66,6 +66,7 @@ static std::optional<std::pair<WalletDescriptor, FlatSigningProvider>> CreateWal
|
|||||||
if (IsTooExpensive(MakeUCharSpan(mocked_descriptor))) return {};
|
if (IsTooExpensive(MakeUCharSpan(mocked_descriptor))) return {};
|
||||||
const auto desc_str{MOCKED_DESC_CONVERTER.GetDescriptor(mocked_descriptor)};
|
const auto desc_str{MOCKED_DESC_CONVERTER.GetDescriptor(mocked_descriptor)};
|
||||||
if (!desc_str.has_value()) return std::nullopt;
|
if (!desc_str.has_value()) return std::nullopt;
|
||||||
|
if (HasTooLargeLeafSize(MakeUCharSpan(*desc_str))) return {};
|
||||||
|
|
||||||
FlatSigningProvider keys;
|
FlatSigningProvider keys;
|
||||||
std::string error;
|
std::string error;
|
||||||
|
|||||||
Reference in new issue
Block a user