Skip to content

Commit

Permalink
fabric-bridge-app: Prevent crash when reading CADMIN cluster on bridg…
Browse files Browse the repository at this point in the history
…e node (#34790)

* Prevent crash when reading CADMIN cluster on dynamic bridge node endpoints

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
tehampson and restyled-commits authored Aug 6, 2024
1 parent 83dc1c8 commit d619f75
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace ::chip;
using namespace ::chip::app::Clusters;

#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
#define ZCL_ADMINISTRATOR_COMMISSIONING_CLUSTER_REVISION (1u)
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)

Expand All @@ -37,9 +38,14 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
AttributeId attributeId = attributeMetadata->attributeId;

BridgedDevice * dev = BridgeDeviceMgr().GetDevice(endpoint);
if (dev != nullptr && clusterId == app::Clusters::BridgedDeviceBasicInformation::Id)
if (dev == nullptr)
{
using namespace app::Clusters::BridgedDeviceBasicInformation::Attributes;
return Protocols::InteractionModel::Status::Failure;
}

if (clusterId == BridgedDeviceBasicInformation::Id)
{
using namespace BridgedDeviceBasicInformation::Attributes;
ChipLogProgress(NotSpecified, "HandleReadBridgedDeviceBasicAttribute: attrId=%d, maxReadLength=%d", attributeId,
maxReadLength);

Expand Down Expand Up @@ -69,6 +75,21 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin
return Protocols::InteractionModel::Status::Success;
}

if (clusterId == AdministratorCommissioning::Id)
{
// TODO(#34791) This is a workaround to prevent crash. CADMIN is still reading incorrect
// Attribute values on dynamic endpoint as it only reads the root node and not the actual bridge
// device we are representing here, when addressing the issue over there we can more easily
// resolve this workaround.
if ((attributeId == AdministratorCommissioning::Attributes::ClusterRevision::Id) && (maxReadLength == 2))
{
uint16_t rev = ZCL_ADMINISTRATOR_COMMISSIONING_CLUSTER_REVISION;
memcpy(buffer, &rev, sizeof(rev));
return Protocols::InteractionModel::Status::Success;
}
return Protocols::InteractionModel::Status::Failure;
}

return Protocols::InteractionModel::Status::Failure;
}

Expand Down

0 comments on commit d619f75

Please sign in to comment.