Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing crashes when comparing objects to nil #34321

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2290,8 +2290,12 @@ + (MTRAttributeRequestPath *)requestPathWithEndpointID:(NSNumber * _Nullable)end

- (BOOL)isEqualToAttributeRequestPath:(MTRAttributeRequestPath *)path
{
return [_endpoint isEqualToNumber:path.endpoint] && [_cluster isEqualToNumber:path.cluster] &&
[_attribute isEqualToNumber:path.attribute];
if (!path)
return NO;
woody-apple marked this conversation as resolved.
Show resolved Hide resolved

return (path.endpoint && [_endpoint isEqualToNumber:path.endpoint])
&& (path.cluster && [_cluster isEqualToNumber:path.cluster])
&& (path.attribute && [_attribute isEqualToNumber:path.attribute]);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2362,8 +2366,12 @@ + (MTREventRequestPath *)requestPathWithEndpointID:(NSNumber * _Nullable)endpoin

- (BOOL)isEqualToEventRequestPath:(MTREventRequestPath *)path
{
return
[_endpoint isEqualToNumber:path.endpoint] && [_cluster isEqualToNumber:path.cluster] && [_event isEqualToNumber:path.event];
if (!path)
return NO;

return (path.endpoint && [_endpoint isEqualToNumber:path.endpoint])
&& (path.cluster && [_cluster isEqualToNumber:path.cluster])
&& (path.event && [_event isEqualToNumber:path.event]);
Comment on lines +2369 to +2374
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as for attribute request paths.

}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2432,7 +2440,11 @@ ConcreteClusterPath path(static_cast<chip::EndpointId>([endpointID unsignedShort

- (BOOL)isEqualToClusterPath:(MTRClusterPath *)clusterPath
{
return [_endpoint isEqualToNumber:clusterPath.endpoint] && [_cluster isEqualToNumber:clusterPath.cluster];
if (!clusterPath)
return NO;
woody-apple marked this conversation as resolved.
Show resolved Hide resolved

return (clusterPath.endpoint && [_endpoint isEqualToNumber:clusterPath.endpoint])
&& (clusterPath.cluster && [_cluster isEqualToNumber:clusterPath.cluster]);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2520,7 +2532,10 @@ ConcreteDataAttributePath path(static_cast<chip::EndpointId>([endpointID unsigne

- (BOOL)isEqualToAttributePath:(MTRAttributePath *)attributePath
{
return [self isEqualToClusterPath:attributePath] && [_attribute isEqualToNumber:attributePath.attribute];
if (!attributePath)
return NO;

return [self isEqualToClusterPath:attributePath] && attributePath.attribute && [_attribute isEqualToNumber:attributePath.attribute];
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2613,7 +2628,10 @@ ConcreteEventPath path(static_cast<chip::EndpointId>([endpointID unsignedShortVa

- (BOOL)isEqualToEventPath:(MTREventPath *)eventPath
{
return [self isEqualToClusterPath:eventPath] && [_event isEqualToNumber:eventPath.event];
if (!eventPath)
return NO;

return [self isEqualToClusterPath:eventPath] && eventPath.event && [_event isEqualToNumber:eventPath.event];
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2703,7 +2721,10 @@ ConcreteCommandPath path(static_cast<chip::EndpointId>([endpointID unsignedShort

- (BOOL)isEqualToCommandPath:(MTRCommandPath *)commandPath
{
return [self isEqualToClusterPath:commandPath] && [_command isEqualToNumber:commandPath.command];
if (!commandPath)
return NO;

return [self isEqualToClusterPath:commandPath] && commandPath.command && [_command isEqualToNumber:commandPath.command];
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)isEqual:(id)object
Expand Down
6 changes: 5 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ - (id)copyWithZone:(NSZone *)zone

- (BOOL)isEqualToClusterData:(MTRDeviceClusterData *)otherClusterData
{
return [_dataVersion isEqual:otherClusterData.dataVersion] && [_attributes isEqual:otherClusterData.attributes];
if (!otherClusterData)
return NO;
woody-apple marked this conversation as resolved.
Show resolved Hide resolved

return (otherClusterData.dataVersion && [_dataVersion isEqual:otherClusterData.dataVersion])
&& (otherClusterData.attributes && [_attributes isEqual:otherClusterData.attributes]);
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

- (BOOL)isEqual:(id)object
Expand Down
Loading