Skip to content

Commit 18ad77e

Browse files
committed
check for userInStorage.currentCredentialCount <= kMaxCredentialsPerUser
1 parent dd3a8e5 commit 18ad77e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

examples/lock-app/silabs/src/LockManager.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, Ember
372372
user.modificationSource = DlAssetSource::kMatterIM;
373373
user.lastModifiedBy = userInStorage.lastModifiedBy;
374374

375+
// Ensure userInStorage.currentCredentialCount <= kMaxCredentialsPerUser to avoid buffer overflow
376+
VerifyOrReturnValue(userInStorage.currentCredentialCount <= kMaxCredentialsPerUser, false);
377+
375378
// Get credential struct from nvm3
376379
chip::StorageKeyName credentialKey = LockUserCredentialMap(userIndex);
377380

@@ -595,7 +598,7 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
595598
static_cast<uint16_t>(sizeof(LockCredentialInfo)));
596599

597600
// Clear credentialInStorage.credentialData
598-
memset(credentialInStorage.credentialData, 0, sizeof(uint8_t)*kMaxCredentialSize);
601+
memset(credentialInStorage.credentialData, 0, sizeof(uint8_t) * kMaxCredentialSize);
599602

600603
if ((error != CHIP_NO_ERROR))
601604
{

0 commit comments

Comments
 (0)