Skip to content

Commit

Permalink
Add missed code review comments (project-chip#28626)
Browse files Browse the repository at this point in the history
* Fix KeySetRemove to fail on key set index 0

Problem:

- Removing KeySet index 0 is not allowed by spec, but SDK allowed it.
- Checking that we ran without accessing fabric is not done, so
  error is FAILURE instead of UNSUPPORTED_ACCESS.
- Fixes project-chip#28518

This PR:

- Adds the check and tests against removing fabric index zero
- Improves error reporting for several errors in the cluster
- Combines validation logic for accessing fabric that was missing

Testing:

- Added unit tests and integration tests for additions
  (except for the unsupported access that requires PASE to check)

* Regen tests with ZAP

* Restyled by clang-format

* Remove explicit check for undefined fabric index

* Fix build

* Rename ValidateAndGetProviderAndFabric to just GetProviderAndFabric

* Added back cleanup for VerifyOrDie argument checking

* Restyle

* Update based on code review comments

* Remove two more flight check comments

* Restyle

* Fix merge error

---------

Co-authored-by: tennessee.carmelveilleux@gmail.com <tennessee@google.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Andrei Litvin <andreilitvin@google.com>
  • Loading branch information
4 people authored Aug 10, 2023
1 parent ceb14fd commit ba490f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,15 @@ void CommandHandler::AddStatusAndLogIfFailure(const ConcreteCommandPath & aComma
ChipLogValueIMStatus(aStatus), aMessage);
}

LogErrorOnFailure(AddStatus(aCommandPath, aStatus));
CHIP_ERROR err = AddStatus(aCommandPath, aStatus);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DataManagement,
"Failed to set status on Endpoint=%u Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI
": %" CHIP_ERROR_FORMAT,
aCommandPath.mEndpointId, ChipLogValueMEI(aCommandPath.mClusterId), ChipLogValueMEI(aCommandPath.mCommandId),
err.Format());
}
}

CHIP_ERROR CommandHandler::AddClusterSpecificSuccess(const ConcreteCommandPath & aCommandPath, ClusterStatus aClusterStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ bool emberAfGroupKeyManagementClusterKeySetWriteCallback(
Credentials::GroupDataProvider * provider = nullptr;
const FabricInfo * fabric = nullptr;

// Flight-check fabric scoping.
if (!GetProviderAndFabric(commandObj, commandPath, &provider, &fabric))
{
// Command will already have status populated from validation.
Expand Down Expand Up @@ -555,7 +554,6 @@ bool emberAfGroupKeyManagementClusterKeySetReadCallback(
Credentials::GroupDataProvider * provider = nullptr;
const FabricInfo * fabric = nullptr;

// Flight-check fabric scoping.
if (!GetProviderAndFabric(commandObj, commandPath, &provider, &fabric))
{
// Command will already have status populated from validation.
Expand Down Expand Up @@ -621,7 +619,6 @@ bool emberAfGroupKeyManagementClusterKeySetRemoveCallback(
Credentials::GroupDataProvider * provider = nullptr;
const FabricInfo * fabric = nullptr;

// Flight-check fabric scoping.
if (!GetProviderAndFabric(commandObj, commandPath, &provider, &fabric))
{
// Command will already have status populated from validation.
Expand Down Expand Up @@ -694,7 +691,6 @@ bool emberAfGroupKeyManagementClusterKeySetReadAllIndicesCallback(
Credentials::GroupDataProvider * provider = nullptr;
const FabricInfo * fabric = nullptr;

// Flight-check fabric scoping.
if (!GetProviderAndFabric(commandObj, commandPath, &provider, &fabric))
{
// Command will already have status populated from validation.
Expand Down

0 comments on commit ba490f6

Please sign in to comment.