Skip to content

Commit

Permalink
Remake ICDMonitoringTable::Find() not to overwrite all entry fields
Browse files Browse the repository at this point in the history
If entry is not found its key handle field must not be filled with
last checked entry when using PSA as it will cause key slot to be
cleared by accident.
  • Loading branch information
maciejbaczmanski committed Aug 12, 2024
1 parent df6f86d commit 5f5d696
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/app/icd/server/ICDMonitoringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,21 @@ CHIP_ERROR ICDMonitoringTable::Get(uint16_t index, ICDMonitoringEntry & entry) c

CHIP_ERROR ICDMonitoringTable::Find(NodeId id, ICDMonitoringEntry & entry)
{
uint16_t index = 0;
while (index < this->Limit())
CHIP_ERROR err;
uint16_t index;
ICDMonitoringEntry tempEntry(mSymmetricKeystore);

for (index = 0; index < this->Limit(); index++)
{
ReturnErrorOnFailure(this->Get(index++, entry));
if (id == entry.checkInNodeID)
SuccessOrExit(err = this->Get(index, tempEntry));
if (id == tempEntry.checkInNodeID)
{
entry = tempEntry;
return CHIP_NO_ERROR;
}
}

exit:
entry.index = index;
return CHIP_ERROR_NOT_FOUND;
}
Expand Down

0 comments on commit 5f5d696

Please sign in to comment.