From 1203500449d1c926c554d951ec8c09498f5e7ea5 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 13 Jun 2022 23:00:43 -0400 Subject: [PATCH] Stop crashing in Low Power cluster Sleep command if there's no delegate. (#19494) We were forgetting to return after sending the error response, so ended up dereferencing the null delegate. Fixes https://github.com/project-chip/connectedhomeip/issues/19481 --- .../low-power-server/low-power-server.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/app/clusters/low-power-server/low-power-server.cpp b/src/app/clusters/low-power-server/low-power-server.cpp index 17cb40c549b425..f7233651943365 100644 --- a/src/app/clusters/low-power-server/low-power-server.cpp +++ b/src/app/clusters/low-power-server/low-power-server.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace chip; using namespace chip::app::Clusters::LowPower; @@ -87,22 +88,23 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) bool emberAfLowPowerClusterSleepCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::Sleep::DecodableType & commandData) { - CHIP_ERROR err = CHIP_NO_ERROR; + using Protocols::InteractionModel::Status; + EndpointId endpoint = commandPath.mEndpointId; Delegate * delegate = GetDelegate(endpoint); - VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); - -exit: - if (err != CHIP_NO_ERROR) + Status status; + if (isDelegateNull(delegate, endpoint)) { - ChipLogError(Zcl, "emberAfLowPowerClusterSleepCallback error: %s", err.AsString()); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + ChipLogError(Zcl, "emberAfLowPowerClusterSleepCallback: no delegate"); + status = Status::Failure; } - - bool success = delegate->HandleSleep(); - EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; - emberAfSendImmediateDefaultResponse(status); + else + { + bool success = delegate->HandleSleep(); + status = success ? Status::Success : Status::Failure; + } + command->AddStatus(commandPath, status); return true; }