Skip to content

Commit a47dcc6

Browse files
Add assertions: Raise assertion failure instead of doing an out-of-bounds read in case of k > sats.size()
Co-authored-by: practicalswift <[email protected]>
1 parent 0d43166 commit a47dcc6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

bitcoin/script/miniscript.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ struct Node {
519519
next_sats.push_back(sats[sats.size() - 1] + sub->ops.sat);
520520
sats = std::move(next_sats);
521521
}
522+
assert(k <= sats.size());
522523
return {stat, sats[k], sats[0]};
523524
}
524525
}
@@ -561,6 +562,7 @@ struct Node {
561562
next_sats.push_back(sats[sats.size() - 1] + sub->ss.sat);
562563
sats = std::move(next_sats);
563564
}
565+
assert(k <= sats.size());
564566
return {sats[k], sats[0]};
565567
}
566568
}
@@ -627,6 +629,7 @@ struct Node {
627629
}
628630
InputStack nsat = ZERO;
629631
for (size_t i = 0; i < k; ++i) nsat = std::move(nsat) + ZERO;
632+
assert(k <= sats.size());
630633
return InputResult(std::move(nsat), std::move(sats[k]));
631634
}
632635
case NodeType::THRESH: {
@@ -643,6 +646,7 @@ struct Node {
643646
for (size_t i = 0; i < sats.size(); ++i) {
644647
if (i != k) nsat = Choose(std::move(nsat), std::move(sats[i]), nonmal);
645648
}
649+
assert(k <= sats.size());
646650
return InputResult(std::move(nsat), std::move(sats[k]));
647651
}
648652
case NodeType::OLDER: {

0 commit comments

Comments
 (0)