Skip to content

Commit

Permalink
fix: edge case in app.isInApplicationsFolder() (#35636)
Browse files Browse the repository at this point in the history
* 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 <jkleinsc@electronjs.org>
  • Loading branch information
2 people authored and electron-bot committed Sep 19, 2022
1 parent 08c02d2 commit bb274e8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions shell/browser/ui/cocoa/electron_bundle_mover.mm
Expand Up @@ -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;
Expand Down

0 comments on commit bb274e8

Please sign in to comment.