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: heap-use-after-free in tray.popUpContextMenu #23182

Merged
merged 1 commit into from Apr 21, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions shell/browser/ui/tray_icon_cocoa.mm
Expand Up @@ -173,8 +173,16 @@ - (void)popUpContextMenu:(electron::AtomMenuModel*)menu_model {
useDefaultAccelerator:NO]);
// Hacky way to mimic design of ordinary tray menu.
[statusItem_ setMenu:[menuController menu]];
// -performClick: is a blocking call, which will run the task loop inside
// itself. This can potentially include running JS, which can result in
// this object being released. We take a temporary reference here to make
// sure we stay alive long enough to successfully return from this
// function.
// TODO(nornagon/codebytere): Avoid nesting task loops here.
[self retain];
[[statusItem_ button] performClick:self];
[statusItem_ setMenu:[menuController_ menu]];
[self release];
return;
}

Expand Down
7 changes: 7 additions & 0 deletions spec-main/api-tray-spec.ts
Expand Up @@ -51,6 +51,13 @@ describe('tray module', () => {
})
tray.popUpContextMenu()
})

it('can be called with a menu', () => {
const menu = Menu.buildFromTemplate([{ label: 'Test' }])
expect(() => {
tray.popUpContextMenu(menu)
}).to.not.throw()
})
})

describe('tray.getBounds()', () => {
Expand Down