From 16edce7ad1e22ecf9fbad553a23c60611568d1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=81=AA=E6=98=8E=E5=8F=89?= Date: Mon, 29 Aug 2022 16:20:51 +0800 Subject: [PATCH] Fix DisarmDone commissionee misssing null check (#22146) * Fix DisarmDone commissionee misssing null check Problem: Obviously invoke commitee pointer is before the null check. In low probability cases, commissioning failure before WiFiNetworkSetup and removing the device connection in the App will cause crash. * Make sure nodeId has a value. --- src/controller/CHIPDeviceController.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index ec8e126137510b..8bcba1f5c06564 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1520,12 +1520,13 @@ void DeviceCommissioner::DisarmDone() // to do here. VerifyOrReturn(mDeviceBeingCommissioned != nullptr); + NodeId nodeId = mDeviceBeingCommissioned->GetDeviceId(); // At this point, we also want to close off the pase session so we need to re-establish - CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice(mDeviceBeingCommissioned->GetDeviceId()); + CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice(nodeId); // Signal completion - this will reset mDeviceBeingCommissioned. CommissioningStageComplete(CHIP_NO_ERROR); - SendCommissioningCompleteCallbacks(commissionee->GetDeviceId(), commissioningCompletionStatus); + SendCommissioningCompleteCallbacks(nodeId, commissioningCompletionStatus); // If we've disarmed the failsafe, it's because we're starting again, so kill the pase connection. if (commissionee != nullptr)