Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edge case in app.isInApplicationsFolder() #35729

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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