Skip to content

Commit

Permalink
Fix read client matching for unsolicited report (#21771)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Jul 18, 2023
1 parent 628961a commit 1078676
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ CHIP_ERROR InteractionModelEngine::ShutdownSubscription(SubscriptionId aSubscrip
{
for (auto * readClient = mpActiveReadClientList; readClient != nullptr; readClient = readClient->GetNextClient())
{
if (readClient->IsSubscriptionType() && readClient->IsMatchingClient(aSubscriptionId))
if (readClient->IsSubscriptionType() && readClient->IsMatchingSubscriptionId(aSubscriptionId))
{
readClient->Close(CHIP_NO_ERROR);
return CHIP_NO_ERROR;
Expand Down Expand Up @@ -538,8 +538,9 @@ Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContex
{
continue;
}

if (!readClient->IsMatchingClient(subscriptionId))
auto peer = apExchangeContext->GetSessionHandle()->GetPeer();
if (readClient->GetFabricIndex() != peer.GetFabricIndex() || readClient->GetPeerNodeId() != peer.GetNodeId() ||
!readClient->IsMatchingSubscriptionId(subscriptionId))
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload)
{
mSubscriptionId = subscriptionId;
}
else if (!IsMatchingClient(subscriptionId))
else if (!IsMatchingSubscriptionId(subscriptionId))
{
err = CHIP_ERROR_INVALID_SUBSCRIPTION;
}
Expand Down Expand Up @@ -838,7 +838,7 @@ CHIP_ERROR ReadClient::ProcessSubscribeResponse(System::PacketBufferHandle && aP

SubscriptionId subscriptionId = 0;
VerifyOrReturnError(subscribeResponse.GetSubscriptionId(&subscriptionId) == CHIP_NO_ERROR, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsMatchingClient(subscriptionId), CHIP_ERROR_INVALID_SUBSCRIPTION);
VerifyOrReturnError(IsMatchingSubscriptionId(subscriptionId), CHIP_ERROR_INVALID_SUBSCRIPTION);
ReturnErrorOnFailure(subscribeResponse.GetMaxInterval(&mMaxInterval));

ChipLogProgress(DataManagement,
Expand Down
2 changes: 1 addition & 1 deletion src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class ReadClient : public Messaging::ExchangeDelegate
SubscriptionActive, ///< The client is maintaining subscription
};

bool IsMatchingClient(SubscriptionId aSubscriptionId)
bool IsMatchingSubscriptionId(SubscriptionId aSubscriptionId)
{
return aSubscriptionId == mSubscriptionId && mInteractionType == InteractionType::Subscribe;
}
Expand Down

0 comments on commit 1078676

Please sign in to comment.