From aa7f89c782279ee6619571de861d84778cd5a865 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 11 Nov 2021 11:48:01 -0500 Subject: [PATCH] Fix chip-tool open-commissioning-window to not crash. (#11645) PairingCommand::RunCommand called mController.RegisterPairingDelegate even in the open-commissioning-window case. Then when the device was connected we'd land in DeviceCommissioner::OnDeviceConnectedFn. This would call OnCommissioningComplete on the pairing delegate, which would land us in PairingCommand::OnCommissioningComplete and thinks the command is done. So we would exit without waiting for an actual response from the server and with exchanges still open. In PairingMode::OpenCommissioningWindow we should not be registering as a pairing delegate and whatnot; we are just sending normal cluster commands. Fixes https://github.com/project-chip/connectedhomeip/issues/11644 --- .../chip-tool/commands/pairing/PairingCommand.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 20fa405af043ad..b8507afb96dc3d 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -36,8 +36,15 @@ CHIP_ERROR PairingCommand::RunCommand() { CHIP_ERROR err = CHIP_NO_ERROR; - mController.RegisterDeviceAddressUpdateDelegate(this); - mController.RegisterPairingDelegate(this); + // If we're OpenCommissioningWindow we don't need to be registered as a + // delegate; we just get notified directly via the callbacks we pass to + // GetConnectedDevice. In fact, if we _do_ register as a delegate we get + // callbacks we don't expect and then weird things happen. + if (mPairingMode != PairingMode::OpenCommissioningWindow) + { + mController.RegisterDeviceAddressUpdateDelegate(this); + mController.RegisterPairingDelegate(this); + } err = RunInternal(mNodeId); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(chipTool, "Init Failure! PairDevice: %s", ErrorStr(err)));