Skip to content

Commit ccaf130

Browse files
Enhance getusedcoinstagstxhashes to handle edge cases (#1775)
* Enhance getusedcoinstagstxhashes to handle edge cases Added a check to ensure that the startNumber does not exceed the available elements in the tags vector. This prevents potential out-of-bounds access and improves the robustness of the function. * Handle negative startNumber for tags tx hashes Co-authored-by: levonpetrosyan93 <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: levonpetrosyan93 <[email protected]>
1 parent fc574a0 commit ccaf130

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/rpc/misc.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,11 +1598,18 @@ UniValue getusedcoinstagstxhashes(const JSONRPCRequest& request)
15981598
tags = sparkState->GetSpendsMobile();
15991599
ltagTxhash = sparkState->GetSpendTxIds();
16001600
}
1601+
1602+
// Handle edge cases: negative startNumber or too large.
1603+
size_t skip = 0;
1604+
if (startNumber > 0) {
1605+
skip = static_cast<size_t>(startNumber);
1606+
if (skip > tags.size()) {
1607+
skip = tags.size();
1608+
}
1609+
}
1610+
16011611
UniValue serializedTagsTxIds(UniValue::VARR);
1602-
int i = 0;
1603-
for ( auto it = tags.begin(); it != tags.end(); ++it, ++i) {
1604-
if (cmp::less((tags.size() - i - 1), startNumber))
1605-
continue;
1612+
for (auto it = tags.begin() + skip; it != tags.end(); ++it) {
16061613
std::vector<unsigned char> serialized;
16071614
serialized.resize(34);
16081615
it->first.serialize(serialized.data());

0 commit comments

Comments
 (0)