From b28d39a0f21ad2a8aaa9e2a852ff64ca239fb842 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Tue, 9 Aug 2022 17:57:40 -0700 Subject: [PATCH] Fix read client matching for unsolicited report (#21771) --- src/app/InteractionModelEngine.cpp | 7 ++++--- src/app/ReadClient.cpp | 4 ++-- src/app/ReadClient.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index ecc6218f90c07e..4232601b669bb5 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -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; @@ -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; } diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 90d4bf77594108..19e1ced153334c 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -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; } @@ -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, diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index dba2e7b7af4924..2b161a7b62e6f5 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -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; }