Skip to content

Commit b30909e

Browse files
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.
1 parent 3bd0730 commit b30909e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/rpc/misc.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,11 +1598,15 @@ UniValue getusedcoinstagstxhashes(const JSONRPCRequest& request)
15981598
tags = sparkState->GetSpendsMobile();
15991599
ltagTxhash = sparkState->GetSpendTxIds();
16001600
}
1601+
1602+
// Handle edge case: startNumber exceeds available elements
1603+
size_t skip = static_cast<size_t>(startNumber);
1604+
if (skip > tags.size()) {
1605+
skip = tags.size();
1606+
}
1607+
16011608
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;
1609+
for (auto it = tags.begin() + skip; it != tags.end(); ++it) {
16061610
std::vector<unsigned char> serialized;
16071611
serialized.resize(34);
16081612
it->first.serialize(serialized.data());

0 commit comments

Comments
 (0)