Skip to content

Commit

Permalink
Fix event buffer size boundary check
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed Feb 22, 2023
1 parent e04478c commit 0893638
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ CHIP_ERROR EventManagement::EnsureSpaceInCircularBuffer(size_t aRequiredSpace)
ReclaimEventCtx ctx;

// check whether we actually need to do anything, exit if we don't
VerifyOrExit(requiredSpace > eventBuffer->AvailableDataLength(), err = CHIP_NO_ERROR);
VerifyOrExit(requiredSpace >= eventBuffer->AvailableDataLength(), err = CHIP_NO_ERROR);

while (true)
{
// check that the request can ultimately be satisfied.
VerifyOrExit(requiredSpace <= eventBuffer->GetTotalDataLength(), err = CHIP_ERROR_BUFFER_TOO_SMALL);

if (requiredSpace > eventBuffer->AvailableDataLength())
if (requiredSpace >= eventBuffer->AvailableDataLength())
{
ctx.mpEventBuffer = eventBuffer;
ctx.mSpaceNeededForMovedEvent = 0;
Expand All @@ -194,7 +194,7 @@ CHIP_ERROR EventManagement::EnsureSpaceInCircularBuffer(size_t aRequiredSpace)
{
VerifyOrExit(ctx.mSpaceNeededForMovedEvent != 0, /* no-op, return err */);
VerifyOrExit(eventBuffer->GetNextCircularEventBuffer() != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
if (ctx.mSpaceNeededForMovedEvent <= eventBuffer->GetNextCircularEventBuffer()->AvailableDataLength())
if (ctx.mSpaceNeededForMovedEvent < eventBuffer->GetNextCircularEventBuffer()->AvailableDataLength())
{
// we can copy the event outright. copy event and
// subsequently evict head s.t. evicting the head
Expand Down

0 comments on commit 0893638

Please sign in to comment.