From bb274e8f88eab32c6bbac3b85e7164e5eea9b913 Mon Sep 17 00:00:00 2001 From: Kishan Bagaria Date: Mon, 19 Sep 2022 23:49:49 +0530 Subject: [PATCH] fix: edge case in app.isInApplicationsFolder() (#35636) * fix: edge case in IsInApplicationsFolder * use realpath instead * lint * revert lowercasing * optimize * Update shell/browser/ui/cocoa/electron_bundle_mover.mm * lint Co-authored-by: John Kleinschmidt --- shell/browser/ui/cocoa/electron_bundle_mover.mm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/shell/browser/ui/cocoa/electron_bundle_mover.mm b/shell/browser/ui/cocoa/electron_bundle_mover.mm index b7e61f97059dc..afeae8305a430 100644 --- a/shell/browser/ui/cocoa/electron_bundle_mover.mm +++ b/shell/browser/ui/cocoa/electron_bundle_mover.mm @@ -182,18 +182,27 @@ return IsInApplicationsFolder([[NSBundle mainBundle] bundlePath]); } +NSString* resolvePath(NSString* path) { + NSString* standardizedPath = [path stringByStandardizingPath]; + char resolved[PATH_MAX]; + if (realpath([standardizedPath UTF8String], resolved) == NULL) + return path; + return @(resolved); +} + bool ElectronBundleMover::IsInApplicationsFolder(NSString* bundlePath) { // Check all the normal Application directories NSArray* applicationDirs = NSSearchPathForDirectoriesInDomains( NSApplicationDirectory, NSAllDomainsMask, true); + NSString* resolvedBundlePath = resolvePath(bundlePath); for (NSString* appDir in applicationDirs) { - if ([bundlePath hasPrefix:appDir]) + if ([resolvedBundlePath hasPrefix:appDir]) return true; } // Also, handle the case that the user has some other Application directory // (perhaps on a separate data partition). - if ([[bundlePath pathComponents] containsObject:@"Applications"]) + if ([[resolvedBundlePath pathComponents] containsObject:@"Applications"]) return true; return false;