From 3d4345381d007d2d4b468300a4a5104ac75a2bea Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 27 Sep 2024 23:00:22 -0400 Subject: [PATCH] Do something sane-ish if someone tries to create MTRDevice with a null nodeID. (#35830) * Do something sane-ish if someone tries to create MTRDevice with a null nodeID. * Add log per review comment. --- src/darwin/Framework/CHIP/MTRDevice.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 6e3e7980583574..bc298b702eb4d0 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -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]; }