From 2608aae65c612241d96dcc61fcbfebd357a1b523 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 25 Apr 2024 21:40:46 -0400 Subject: [PATCH] Fix handling of non-permitted messages in ExchangeContext. (#33148) They should not count as responses, since we don't notify our delegate about them. --- src/messaging/ExchangeContext.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 1b93bff5a62e62..49431951a60c6e 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -592,21 +592,26 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload // Set kFlagReceivedAtLeastOneMessage to true since we have received at least one new application level message SetHasReceivedAtLeastOneMessage(true); - if (IsResponseExpected()) + // Don't send messages on to our delegate if our dispatch does not allow + // those messages. Those messages should also not be treated as responses, + // since if our delegate is expecting a response we will not notify it about + // these messages. + if (mDispatch.MessagePermitted(payloadHeader.GetProtocolID(), payloadHeader.GetMessageType())) { - // Since we got the response, cancel the response timer. - CancelResponseTimer(); + if (IsResponseExpected()) + { + // Since we got the response, cancel the response timer. + CancelResponseTimer(); - // If the context was expecting a response to a previously sent message, this message - // is implicitly that response. - SetResponseExpected(false); - } + // If the context was expecting a response to a previously sent message, this message + // is implicitly that response. + SetResponseExpected(false); + } - // Don't send messages on to our delegate if our dispatch does not allow - // those messages. - if (mDelegate != nullptr && mDispatch.MessagePermitted(payloadHeader.GetProtocolID(), payloadHeader.GetMessageType())) - { - return mDelegate->OnMessageReceived(this, payloadHeader, std::move(msgBuf)); + if (mDelegate != nullptr) + { + return mDelegate->OnMessageReceived(this, payloadHeader, std::move(msgBuf)); + } } DefaultOnMessageReceived(this, payloadHeader.GetProtocolID(), payloadHeader.GetMessageType(), messageCounter,