From 362d57060f0ab8e4d09ace259bcc9c07e17c6437 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Mon, 1 Aug 2022 21:10:27 -0700 Subject: [PATCH] Make sure we don't crash when commissioning with no pairing delegate. (#21505) (#21514) Fixes https://github.com/project-chip/connectedhomeip/issues/21492 Co-authored-by: Boris Zbarsky --- src/controller/CHIPDeviceController.cpp | 5 ++++- src/controller/SetUpCodePairer.cpp | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 929b42c92509f9..7bd3fe0e30915c 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -924,7 +924,10 @@ void DeviceCommissioner::OnSessionEstablished(const SessionHandle & session) ChipLogDetail(Controller, "Remote device completed SPAKE2+ handshake"); - mPairingDelegate->OnPairingComplete(CHIP_NO_ERROR); + if (mPairingDelegate != nullptr) + { + mPairingDelegate->OnPairingComplete(CHIP_NO_ERROR); + } if (mRunCommissioningAfterConnection) { diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 12b6b3cf1e0bb5..0e72ddaeca3b3b 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -436,7 +436,10 @@ void SetUpCodePairer::OnPairingComplete(CHIP_ERROR error) mSystemLayer->CancelTimer(OnDeviceDiscoveredTimeoutCallback, this); ResetDiscoveryState(); - pairingDelegate->OnPairingComplete(error); + if (pairingDelegate != nullptr) + { + pairingDelegate->OnPairingComplete(error); + } return; } @@ -449,7 +452,10 @@ void SetUpCodePairer::OnPairingComplete(CHIP_ERROR error) return; } - pairingDelegate->OnPairingComplete(error); + if (pairingDelegate != nullptr) + { + pairingDelegate->OnPairingComplete(error); + } } void SetUpCodePairer::OnPairingDeleted(CHIP_ERROR error)