From 37e53f6a88b6ae8fd1cc2c9870851ba1607ce290 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 5 Dec 2024 11:49:37 -0500 Subject: [PATCH] Check whether we actually have a GroupId before trying to use it. (#36729) This avoids a crash on malformed messages (which will get dropped further down the pipeline, due to not being valid). Fixes https://github.com/project-chip/connectedhomeip/issues/36711 Co-authored-by: Andrei Litvin --- src/messaging/ExchangeMgr.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index b977c73b072d84..fad088bd523a67 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -284,8 +284,15 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const } else { - ChipLogProgress(ExchangeManager, "Received Groupcast Message with GroupId 0x%04X (%d)", - packetHeader.GetDestinationGroupId().Value(), packetHeader.GetDestinationGroupId().Value()); + if (packetHeader.GetDestinationGroupId().HasValue()) + { + ChipLogProgress(ExchangeManager, "Received Groupcast Message with GroupId 0x%04X (%d)", + packetHeader.GetDestinationGroupId().Value(), packetHeader.GetDestinationGroupId().Value()); + } + else + { + ChipLogProgress(ExchangeManager, "Received Groupcast Message without GroupId"); + } } // Do not handle messages that don't match an existing exchange on an