The RCFactory.getMarketInfo function uses the same counter _resultNumber for the result arrays' index.
This counter is increased if _skipResults is set, and the arrays are therefore not indexed at zero.
if (_resultNumber < _skipResults) {
// @audit increases the array index
_resultNumber++;
} else {
// @audit will start at a higher number if _skipResults is set
_marketAddresses[_resultNumber] = _market;
_ipfsHashes[_resultNumber] = ipfsHash[_market];
_slugs[_resultNumber] = addressToSlug[_market];
_potSizes[_resultNumber] = IRCMarket(_market)
.totalRentCollected();
_resultNumber++;
}
Imagine _skipResults = marketInfoResults to receive the second "page" of market infos. The function will just return an empty array of size marketInfoResults because of the while(_resultNumber < marketInfoResults) condition and increasing this same counter when skipping results.
Impact
The function does not return the correct market infos if _skipResults is used.
Recommended Mitigation Steps
The _resultNumber which is the index to the result arrays may not be increased when skipping results, instead a different counter should be used.
The easiest way to fix this is by just decrementing the _skipResults variable itself.
Change the if (_resultNumber < _skipResults) condition to:
if (IRCMarket(_market).state() == IRCMarket.States(_state)) {
if (_skipResults > 0) {
_skipResults--;
} else {
// same old
}
}
Handle
cmichel
Vulnerability details
The
RCFactory.getMarketInfo
function uses the same counter_resultNumber
for the result arrays' index. This counter is increased if_skipResults
is set, and the arrays are therefore not indexed at zero.Imagine
_skipResults = marketInfoResults
to receive the second "page" of market infos. The function will just return an empty array of sizemarketInfoResults
because of thewhile(_resultNumber < marketInfoResults)
condition and increasing this same counter when skipping results.Impact
The function does not return the correct market infos if
_skipResults
is used.Recommended Mitigation Steps
The
_resultNumber
which is the index to the result arrays may not be increased when skipping results, instead a different counter should be used. The easiest way to fix this is by just decrementing the_skipResults
variable itself. Change theif (_resultNumber < _skipResults)
condition to: