Skip to content

Commit

Permalink
[Darwin] Support MTRCommandWithRequiredResponse being nested in XPC (p…
Browse files Browse the repository at this point in the history
…roject-chip#37506)

* [Darwin] Support MTRCommandWithRequiredResponse being nested in XPC

When secure decoding MTRCommandWithRequiredResponse as part of
[MTRDevice deviceController:nodeID:invokeCommands:completion:], it needs
to list all classes that be part of the commandFields and
requiredResponse fields. When double nested XPC will only assume to
decode NSDictionary of basic type.

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
anush-apple and restyled-commits authored Feb 11, 2025
1 parent 91c2b7e commit 03fe653
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRCommandWithRequiredResponse.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)decoder
return nil;
}

_commandFields = [decoder decodeObjectOfClass:NSDictionary.class forKey:sFieldsKey];
_commandFields = [decoder decodeObjectOfClasses:[NSSet setWithArray:@[ [NSDictionary class], [NSString class], [NSNumber class], [NSArray class], [NSData class] ]] forKey:sFieldsKey];
if (_commandFields) {
if (![_commandFields isKindOfClass:NSDictionary.class]) {
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded %@ for commandFields, not NSDictionary.", _commandFields);
Expand All @@ -79,7 +79,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)decoder
}
}

_requiredResponse = [decoder decodeObjectOfClass:NSDictionary.class forKey:sExpectedResultKey];
_requiredResponse = [decoder decodeObjectOfClasses:[NSSet setWithArray:@[ [NSDictionary class], [NSString class], [NSNumber class], [NSArray class], [NSData class] ]] forKey:sExpectedResultKey];
if (_requiredResponse) {
if (![_requiredResponse isKindOfClass:NSDictionary.class]) {
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded %@ for requiredResponse, not NSDictionary.", _requiredResponse);
Expand Down

0 comments on commit 03fe653

Please sign in to comment.