Skip to content

Commit

Permalink
Merge #63: Ensure that string is hex before calling ParseHex
Browse files Browse the repository at this point in the history
cdfde60 Ensure that string is hex before calling ParseHex (Samuel Dobson)

Pull request description:

  Fixes #23, fixes #25

  ParseHex has no check that the string is valid, so we need to call IsHex() beforehand.

ACKs for top commit:
  sipa:
    utACK cdfde60

Tree-SHA512: 1d77b34694f0d8aa23a490f9bcaf138ff87a84e35b6e57fb5fd8a89c7cc99e8fb0dae3d8033ab6a52ea4f041504db710e3edaab439cfc41498309c5ee8fcb929
  • Loading branch information
sipa committed Aug 19, 2021
2 parents f7de269 + cdfde60 commit 97e9279
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 97e9279

Please sign in to comment.