From 28da08fbdcba82144be73ebffc9cf2f9a0be660f Mon Sep 17 00:00:00 2001 From: dinabenamar <108664279+dinabenamar@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:44:00 +0100 Subject: [PATCH 1/2] [Zephyr] Make include of "zephyr/bluetooth/hci.h" explicit (#32461) --- src/platform/Zephyr/BLEManagerImpl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/Zephyr/BLEManagerImpl.cpp b/src/platform/Zephyr/BLEManagerImpl.cpp index 09ddd4fbe34304..07f30dc0632a6c 100644 --- a/src/platform/Zephyr/BLEManagerImpl.cpp +++ b/src/platform/Zephyr/BLEManagerImpl.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include #include From 9df9200315edae7290df46c484a91d59c63d7b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Kr=C3=B3lik?= <66667989+Damian-Nordic@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:15:10 +0100 Subject: [PATCH 2/2] [app] Do not crash if CommandHandler fails to allocate packet (#32463) CommandHandler uses VerifyOrDie when adding a status to be sent to the requestor. If the device runs out packet buffers and CommandHandler fails to allocate a packet for the status, the device crashes. Triggering the crash requires many commands to arrive in the device around the same time, which is rare but possible. Signed-off-by: Damian Krolik --- src/app/CommandHandler.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index d0e5db94197e0d..8170b57abd7d23 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -595,7 +595,17 @@ void CommandHandler::AddStatus(const ConcreteCommandPath & aCommandPath, const P { // Return early in case of requests targeted to a group, since they should not add a response. VerifyOrReturn(!IsGroupRequest()); - VerifyOrDie(FallibleAddStatus(aCommandPath, aStatus, context) == CHIP_NO_ERROR); + + CHIP_ERROR error = FallibleAddStatus(aCommandPath, aStatus, context); + + if (error != CHIP_NO_ERROR) + { + ChipLogError(DataManagement, "Failed to add command status: %" CHIP_ERROR_FORMAT, error.Format()); + + // Do not crash if the status has not been added due to running out of packet buffers or other resources. + // It is better to drop a single response than to go offline and lose all sessions and subscriptions. + VerifyOrDie(error == CHIP_ERROR_NO_MEMORY); + } } CHIP_ERROR CommandHandler::FallibleAddStatus(const ConcreteCommandPath & path, const Protocols::InteractionModel::Status status,