Skip to content

Commit

Permalink
Do something sane-ish if someone tries to create MTRDevice with a nul…
Browse files Browse the repository at this point in the history
…l nodeID. (#35830)

* Do something sane-ish if someone tries to create MTRDevice with a null nodeID.

* Add log per review comment.
  • Loading branch information
bzbarsky-apple committed Sep 28, 2024
1 parent 1608171 commit 3d43453
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ - (void)dealloc

+ (MTRDevice *)deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
{
if (nodeID == nil || controller == nil) {
// These are not nullable in our API, but clearly someone is not
// actually turning on the relevant compiler checks (or is doing dynamic
// dispatch with bad values). While we promise to not return nil from
// this method, if the caller is ignoring the nullability API contract,
// there's not much we can do here.
MTR_LOG_ERROR("Can't create device with nodeID: %@, controller: %@",
nodeID, controller);
return nil;
}

return [controller deviceForNodeID:nodeID];
}

Expand Down

0 comments on commit 3d43453

Please sign in to comment.