Skip to content

Commit 4e74117

Browse files
committed
[app] Do not crash if CommandHandler fails to allocate packet
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 <damian.krolik@nordicsemi.no>
1 parent e52724f commit 4e74117

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/app/CommandHandler.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,17 @@ void CommandHandler::AddStatus(const ConcreteCommandPath & aCommandPath, const P
595595
{
596596
// Return early in case of requests targeted to a group, since they should not add a response.
597597
VerifyOrReturn(!IsGroupRequest());
598-
VerifyOrDie(FallibleAddStatus(aCommandPath, aStatus, context) == CHIP_NO_ERROR);
598+
599+
CHIP_ERROR error = FallibleAddStatus(aCommandPath, aStatus, context);
600+
601+
if (error != CHIP_NO_ERROR)
602+
{
603+
ChipLogError(DataManagement, "Failed to add command status: %" CHIP_ERROR_FORMAT, error.Format());
604+
605+
// Do not crash if the status has not been added due to running out of packet buffers or other resources.
606+
// It is better to drop a single response than to go offline and lose all sessions and subscriptions.
607+
VerifyOrDie(error == CHIP_ERROR_NO_MEMORY);
608+
}
599609
}
600610

601611
CHIP_ERROR CommandHandler::FallibleAddStatus(const ConcreteCommandPath & path, const Protocols::InteractionModel::Status status,

0 commit comments

Comments
 (0)