From 41bf76ef85fb87f7f26d9767f5c22edca946add1 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Sun, 25 Apr 2021 13:11:40 -0700 Subject: [PATCH 1/3] [Darwin] Fix a crash when a nil device is passed to a cluster on init --- .../zap-templates/templates/app/CHIPClustersObjc-src.zapt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/zap-templates/templates/app/CHIPClustersObjc-src.zapt b/src/app/zap-templates/templates/app/CHIPClustersObjc-src.zapt index b40dc2054e7b53..3cbd2ed6f402e1 100644 --- a/src/app/zap-templates/templates/app/CHIPClustersObjc-src.zapt +++ b/src/app/zap-templates/templates/app/CHIPClustersObjc-src.zapt @@ -470,6 +470,11 @@ private: return nil; } + if (device == nullptr) + { + return nil; + } + CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint); if (err != CHIP_NO_ERROR) { return nil; From f2854de036068ab4900cd7fff783acef59ccc9f8 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Sun, 25 Apr 2021 13:15:59 -0700 Subject: [PATCH 2/3] Update generated files --- examples/chip-tool/gen/CHIPClustersObjc.mm | 4 ++++ src/controller/python/gen/CHIPClustersObjc.mm | 4 ++++ src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/examples/chip-tool/gen/CHIPClustersObjc.mm b/examples/chip-tool/gen/CHIPClustersObjc.mm index 3d112f08b8633c..983cf4921a84ce 100644 --- a/examples/chip-tool/gen/CHIPClustersObjc.mm +++ b/examples/chip-tool/gen/CHIPClustersObjc.mm @@ -2192,6 +2192,10 @@ - (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoin return nil; } + if (device == nullptr) { + return nil; + } + CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint); if (err != CHIP_NO_ERROR) { return nil; diff --git a/src/controller/python/gen/CHIPClustersObjc.mm b/src/controller/python/gen/CHIPClustersObjc.mm index 5900a62c769911..e7eb0a6702d5bb 100644 --- a/src/controller/python/gen/CHIPClustersObjc.mm +++ b/src/controller/python/gen/CHIPClustersObjc.mm @@ -1791,6 +1791,10 @@ - (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoin return nil; } + if (device == nullptr) { + return nil; + } + CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint); if (err != CHIP_NO_ERROR) { return nil; diff --git a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm index d9c412b58dc2f8..5faf5f6e3cd904 100644 --- a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm +++ b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm @@ -2085,6 +2085,10 @@ - (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoin return nil; } + if (device == nullptr) { + return nil; + } + CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint); if (err != CHIP_NO_ERROR) { return nil; From 8798e3b91aecff4a22c1c08d96ea30a83e8fdfba Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Sun, 25 Apr 2021 15:20:49 -0700 Subject: [PATCH 3/3] Mark getDevice as nullable since it can return nil --- src/darwin/Framework/CHIP/CHIPDeviceController.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/CHIPDeviceController.h b/src/darwin/Framework/CHIP/CHIPDeviceController.h index 2c7c9e4952bc28..4079f169965efd 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceController.h +++ b/src/darwin/Framework/CHIP/CHIPDeviceController.h @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)stopDevicePairing:(uint64_t)deviceID error:(NSError * __autoreleasing *)error; - (void)updateDevice:(uint64_t)deviceID fabricId:(uint64_t)fabricId; -- (CHIPDevice *)getPairedDevice:(uint64_t)deviceID error:(NSError * __autoreleasing *)error; +- (nullable CHIPDevice *)getPairedDevice:(uint64_t)deviceID error:(NSError * __autoreleasing *)error; - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE;