Skip to content

Commit

Permalink
Fix DeviceProxy selection in AutoCommissioner. (#22294)
Browse files Browse the repository at this point in the history
Before #21256
AutoCommissioner used the operational proxy if it existed at all.  This could
happen even if it was disconnected, as long as it had been connected at some
point in the past.

This was accidentally changed to "use the operational proxy only if it's
connected" in #21256.

This can lead to a crash, as described in
#22268 (comment),
if shutdown happens after the operational proxy is connected but before we get
a response to CommissioningComplete.  In that case, we will evict our CASE
session, which will error out the CommissioningComplete command we sent and try
to clean up, but it will select the (now dangling!) mCommissioneeDeviceProxy
instead of correctly selecting mOperationalDeviceProxy, because the
mOperationalDeviceProxy no longer has a session at that point.

The fix is to check for an "initialized" (in the sense that it has a valid peer
node id) mOperationalDeviceProxy instead of checking for a connected one.  This
matches the semantics of the check we used to have before
#21256.

Fixes #22293
  • Loading branch information
bzbarsky-apple authored Aug 31, 2022
1 parent 70253a8 commit bd32efa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio
DeviceProxy * AutoCommissioner::GetDeviceProxyForStep(CommissioningStage nextStage)
{
if (nextStage == CommissioningStage::kSendComplete ||
(nextStage == CommissioningStage::kCleanup && mOperationalDeviceProxy.ConnectionReady()))
(nextStage == CommissioningStage::kCleanup && mOperationalDeviceProxy.GetDeviceId() != kUndefinedNodeId))
{
return &mOperationalDeviceProxy;
}
Expand Down

0 comments on commit bd32efa

Please sign in to comment.