Skip to content

Commit

Permalink
Add assertions: Raise assertion failure instead of doing an out-of-bo…
Browse files Browse the repository at this point in the history
…unds read in case of k > sats.size()

Co-authored-by: practicalswift <practicalswift@users.noreply.github.com>
  • Loading branch information
sanket1729 and practicalswift committed Aug 5, 2021
1 parent 0d43166 commit a47dcc6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bitcoin/script/miniscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ struct Node {
next_sats.push_back(sats[sats.size() - 1] + sub->ops.sat);
sats = std::move(next_sats);
}
assert(k <= sats.size());
return {stat, sats[k], sats[0]};
}
}
Expand Down Expand Up @@ -561,6 +562,7 @@ struct Node {
next_sats.push_back(sats[sats.size() - 1] + sub->ss.sat);
sats = std::move(next_sats);
}
assert(k <= sats.size());
return {sats[k], sats[0]};
}
}
Expand Down Expand Up @@ -627,6 +629,7 @@ struct Node {
}
InputStack nsat = ZERO;
for (size_t i = 0; i < k; ++i) nsat = std::move(nsat) + ZERO;
assert(k <= sats.size());
return InputResult(std::move(nsat), std::move(sats[k]));
}
case NodeType::THRESH: {
Expand All @@ -643,6 +646,7 @@ struct Node {
for (size_t i = 0; i < sats.size(); ++i) {
if (i != k) nsat = Choose(std::move(nsat), std::move(sats[i]), nonmal);
}
assert(k <= sats.size());
return InputResult(std::move(nsat), std::move(sats[k]));
}
case NodeType::OLDER: {
Expand Down

0 comments on commit a47dcc6

Please sign in to comment.