The RingBufferLib.newestIndex returns _cardinality - 1 if _nextIndex = 0.
This is correct if the buffer's capacity is at a maximum, but wrong if it has just been created.
Impact
The TwabLib.newestTwab function returns _twabs[MAX_CARDINALITY - 1].
As everything is uninitialized at this point, it should not lead to issues though but other functions using newestIndex could.
Recommended Mitigation Steps
Returning 0 in this case seems more sensible?
Anyway, before accessing any buffer, it should be checked if it has any elements in it, otherwise, short-circuit with a default value.
Handle
cmichel
Vulnerability details
The
RingBufferLib.newestIndex
returns_cardinality - 1
if_nextIndex = 0
. This is correct if the buffer's capacity is at a maximum, but wrong if it has just been created.Impact
The
TwabLib.newestTwab
function returns_twabs[MAX_CARDINALITY - 1]
. As everything is uninitialized at this point, it should not lead to issues though but other functions usingnewestIndex
could.Recommended Mitigation Steps
Returning
0
in this case seems more sensible? Anyway, before accessing any buffer, it should be checked if it has any elements in it, otherwise, short-circuit with a default value.