From 3b5bb01310560303008584d07ffc502851e968b5 Mon Sep 17 00:00:00 2001 From: Jeff Tung <100387939+jtung-apple@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:24:06 -0700 Subject: [PATCH] [Darwin] XPC interface for invoke needs to take into account the reply may contain non-property-list objects (#35131) --- .../Framework/CHIP/MTRDeviceController_XPC.mm | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm b/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm index 31acadcce576d3..7111aa4eb7f2bd 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm @@ -43,6 +43,21 @@ @implementation MTRDeviceController_XPC @synthesize uniqueIdentifier = _uniqueIdentifier; +- (NSXPCInterface *)_interfaceForServerProtocol +{ + NSXPCInterface * interface = [NSXPCInterface interfaceWithProtocol:@protocol(MTRXPCServerProtocol)]; + + NSSet * allowedClasses = [NSSet setWithArray:@[ + [NSString class], [NSNumber class], [NSData class], [NSArray class], [NSDictionary class], [NSError class], [MTRCommandPath class], [MTRAttributePath class] + ]]; + + [interface setClasses:allowedClasses + forSelector:@selector(deviceController:nodeID:invokeCommandWithEndpointID:clusterID:commandID:commandFields:expectedValues:expectedValueInterval:timedInvokeTimeout:completion:) + argumentIndex:0 + ofReply:YES]; + return interface; +} + - (NSXPCInterface *)_interfaceForClientProtocol { NSXPCInterface * interface = [NSXPCInterface interfaceWithProtocol:@protocol(MTRXPCClientProtocol)]; @@ -84,7 +99,7 @@ - (id)initWithUniqueIdentifier:(NSUUID *)UUID xpConnectionBlock:(NSXPCConnection MTR_LOG("Set up XPC Connection: %@", self.xpcConnection); if (self.xpcConnection) { - self.xpcConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MTRXPCServerProtocol)]; + self.xpcConnection.remoteObjectInterface = [self _interfaceForServerProtocol]; self.xpcConnection.exportedInterface = [self _interfaceForClientProtocol]; self.xpcConnection.exportedObject = self; @@ -118,9 +133,9 @@ - (id)initWithUniqueIdentifier:(NSUUID *)UUID machServiceName:(NSString *)machSe MTR_LOG("Set up XPC Connection: %@", self.xpcConnection); if (self.xpcConnection) { - self.xpcConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MTRXPCServerProtocol)]; + self.xpcConnection.remoteObjectInterface = [self _interfaceForServerProtocol]; - self.xpcConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MTRXPCClientProtocol)]; + self.xpcConnection.exportedInterface = [self _interfaceForClientProtocol]; self.xpcConnection.exportedObject = self; MTR_LOG("%s: resuming new XPC connection");