Skip to content

Commit

Permalink
Ensure that string is hex before calling ParseHex
Browse files Browse the repository at this point in the history
  • Loading branch information
meshcollider committed Aug 19, 2021
1 parent f7de269 commit cdfde60
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions bitcoin/script/miniscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,19 +900,27 @@ inline NodeRef<Key> Parse(Span<const char>& in, const Ctx& ctx, int recursion_de
} else if (expr == MakeSpan("1")) {
return MakeNodeRef<Key>(NodeType::JUST_1);
} else if (Func("sha256", expr)) {
auto hash = ParseHex(std::string(expr.begin(), expr.end()));
std::string val = std::string(expr.begin(), expr.end());
if (!IsHex(val)) return {};
auto hash = ParseHex(val);
if (hash.size() != 32) return {};
return MakeNodeRef<Key>(NodeType::SHA256, std::move(hash));
} else if (Func("ripemd160", expr)) {
auto hash = ParseHex(std::string(expr.begin(), expr.end()));
std::string val = std::string(expr.begin(), expr.end());
if (!IsHex(val)) return {};
auto hash = ParseHex(val);
if (hash.size() != 20) return {};
return MakeNodeRef<Key>(NodeType::RIPEMD160, std::move(hash));
} else if (Func("hash256", expr)) {
auto hash = ParseHex(std::string(expr.begin(), expr.end()));
std::string val = std::string(expr.begin(), expr.end());
if (!IsHex(val)) return {};
auto hash = ParseHex(val);
if (hash.size() != 32) return {};
return MakeNodeRef<Key>(NodeType::HASH256, std::move(hash));
} else if (Func("hash160", expr)) {
auto hash = ParseHex(std::string(expr.begin(), expr.end()));
std::string val = std::string(expr.begin(), expr.end());
if (!IsHex(val)) return {};
auto hash = ParseHex(val);
if (hash.size() != 20) return {};
return MakeNodeRef<Key>(NodeType::HASH160, std::move(hash));
} else if (Func("after", expr)) {
Expand Down

0 comments on commit cdfde60

Please sign in to comment.