From 3153159658855b361e8c2a8209933c48c032e567 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 20 Jun 2022 16:16:04 -0700 Subject: [PATCH] [Sandbox] Make Sandbox prefer the longest path The Sandbox Broker should prefer the token with the longest matching path, not the shortest. Signed-off-by: Christopher Snowhill --- Utils/SandboxBroker.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utils/SandboxBroker.m b/Utils/SandboxBroker.m index 750e66dd7..667e1976b 100644 --- a/Utils/SandboxBroker.m +++ b/Utils/SandboxBroker.m @@ -130,7 +130,7 @@ static NSURL *urlWithoutFragment(NSURL *u) { NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"path" ascending:NO]; - for(size_t i = 1; i <= [pathComponents count]; ++i) { + for(size_t i = [pathComponents count]; i > 0; --i) { NSArray *partialComponents = [pathComponents subarrayWithRange:NSMakeRange(0, i)]; NSURL *partialUrl = [NSURL fileURLWithPathComponents:partialComponents]; NSString *matchString = [[partialUrl path] stringByAppendingString:@"*"]; @@ -173,7 +173,7 @@ static NSURL *urlWithoutFragment(NSURL *u) { NSPersistentContainer *pc = [NSApp sharedPersistentContainer]; - for(size_t i = 1; i <= [pathComponents count]; ++i) { + for(size_t i = [pathComponents count]; i > 0; --i) { NSArray *partialComponents = [pathComponents subarrayWithRange:NSMakeRange(0, i)]; NSURL *partialUrl = [NSURL fileURLWithPathComponents:partialComponents]; NSString *matchString = [[partialUrl path] stringByAppendingString:@"*"];