Skip to content

Commit dd3a8e5

Browse files
committed
add endpoint verification to each function
1 parent 158d766 commit dd3a8e5

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

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

+25-2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, Ember
327327

328328
VerifyOrReturnValue(IsValidUserIndex(userIndex), false);
329329

330+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, false);
331+
330332
ChipLogProgress(Zcl, "Door Lock App: LockManager::GetUser [endpoint=%d,userIndex=%hu]", endpointId, userIndex);
331333

332334
chip::StorageKeyName userKey = LockUserEndpoint(userIndex, endpointId);
@@ -419,14 +421,14 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip:
419421
endpointId, userIndex, creator, modifier, userName.data(), uniqueId, to_underlying(userStatus),
420422
to_underlying(usertype), to_underlying(credentialRule), credentials, totalCredentials);
421423

424+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, false);
425+
422426
VerifyOrReturnValue(userIndex > 0, false); // indices are one-indexed
423427

424428
userIndex--;
425429

426430
VerifyOrReturnValue(IsValidUserIndex(userIndex), false);
427431

428-
VerifyOrReturnValue(kInvalidEndpointId != endpointId, false);
429-
430432
if (userName.size() > DOOR_LOCK_MAX_USER_NAME_SIZE)
431433
{
432434
ChipLogError(Zcl, "Cannot set user - user name is too long [endpoint=%d,index=%d]", endpointId, userIndex);
@@ -485,6 +487,8 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
485487
{
486488
CHIP_ERROR error;
487489

490+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, false);
491+
488492
VerifyOrReturnValue(IsValidCredentialType(credentialType), false);
489493

490494
if (CredentialTypeEnum::kProgrammingPIN == credentialType)
@@ -552,6 +556,8 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
552556
{
553557
CHIP_ERROR error;
554558

559+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, false);
560+
555561
VerifyOrReturnValue(IsValidCredentialType(credentialType), false);
556562

557563
if (CredentialTypeEnum::kProgrammingPIN == credentialType)
@@ -588,6 +594,9 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
588594
chip::Server::GetInstance().GetPersistentStorage().SyncSetKeyValue(key.KeyName(), &credentialInStorage,
589595
static_cast<uint16_t>(sizeof(LockCredentialInfo)));
590596

597+
// Clear credentialInStorage.credentialData
598+
memset(credentialInStorage.credentialData, 0, sizeof(uint8_t)*kMaxCredentialSize);
599+
591600
if ((error != CHIP_NO_ERROR))
592601
{
593602
ChipLogError(Zcl, "Error reading from KVS key");
@@ -604,6 +613,8 @@ DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we
604613
{
605614
CHIP_ERROR error;
606615

616+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, DlStatus::kFailure);
617+
607618
VerifyOrReturnValue(weekdayIndex > 0, DlStatus::kFailure); // indices are one-indexed
608619
VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed
609620

@@ -653,6 +664,8 @@ DlStatus LockManager::SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t we
653664
{
654665
CHIP_ERROR error;
655666

667+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, DlStatus::kFailure);
668+
656669
VerifyOrReturnValue(weekdayIndex > 0, DlStatus::kFailure); // indices are one-indexed
657670
VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed
658671

@@ -689,6 +702,8 @@ DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye
689702
{
690703
CHIP_ERROR error;
691704

705+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, DlStatus::kFailure);
706+
692707
VerifyOrReturnValue(yearDayIndex > 0, DlStatus::kFailure); // indices are one-indexed
693708
VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed
694709

@@ -737,6 +752,8 @@ DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t ye
737752
{
738753
CHIP_ERROR error;
739754

755+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, DlStatus::kFailure);
756+
740757
VerifyOrReturnValue(yearDayIndex > 0, DlStatus::kFailure); // indices are one-indexed
741758
VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed
742759

@@ -770,6 +787,8 @@ DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho
770787
{
771788
CHIP_ERROR error;
772789

790+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, DlStatus::kFailure);
791+
773792
VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed
774793

775794
holidayIndex--;
@@ -815,6 +834,8 @@ DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t ho
815834
{
816835
CHIP_ERROR error;
817836

837+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, DlStatus::kFailure);
838+
818839
VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed
819840

820841
holidayIndex--;
@@ -867,6 +888,8 @@ bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable<chip:
867888

868889
CHIP_ERROR error;
869890

891+
VerifyOrReturnValue(kInvalidEndpointId != endpointId, false);
892+
870893
// Assume pin is required until told otherwise
871894
bool requirePin = true;
872895
chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(endpointId, &requirePin);

0 commit comments

Comments
 (0)