From dfd77704e62f2bcb236787f685bec90895ab9586 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 10 Aug 2022 16:48:06 +0200 Subject: [PATCH] sandbox - mitigate native crash from `ipcRenderer` usages (#157765) (#157794) --- .../sharedProcess/sharedProcessMain.ts | 2 +- .../terminalNativeContribution.ts | 2 +- src/vs/workbench/electron-sandbox/window.ts | 48 ++++++++++--------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts index 2e6d00020c04e6..fc42278acc881c 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts @@ -133,7 +133,7 @@ class SharedProcessMain extends Disposable { // application is shutting down anyways. // const eventName = 'vscode:electron-main->shared-process=disposeWorker'; - const onDisposeWorker = (event: unknown, configuration: ISharedProcessWorkerConfiguration) => this.onDisposeWorker(configuration); + const onDisposeWorker = (event: unknown, configuration: ISharedProcessWorkerConfiguration) => { this.onDisposeWorker(configuration); }; ipcRenderer.on(eventName, onDisposeWorker); this._register(toDisposable(() => ipcRenderer.removeListener(eventName, onDisposeWorker))); } diff --git a/src/vs/workbench/contrib/terminal/electron-sandbox/terminalNativeContribution.ts b/src/vs/workbench/contrib/terminal/electron-sandbox/terminalNativeContribution.ts index 33ab2ec5a95448..b22ebddac85e0f 100644 --- a/src/vs/workbench/contrib/terminal/electron-sandbox/terminalNativeContribution.ts +++ b/src/vs/workbench/contrib/terminal/electron-sandbox/terminalNativeContribution.ts @@ -27,7 +27,7 @@ export class TerminalNativeContribution extends Disposable implements IWorkbench ) { super(); - ipcRenderer.on('vscode:openFiles', (_: unknown, request: INativeOpenFileRequest) => this._onOpenFileRequest(request)); + ipcRenderer.on('vscode:openFiles', (_: unknown, request: INativeOpenFileRequest) => { this._onOpenFileRequest(request); }); this._register(nativeHostService.onDidResumeOS(() => this._onOsResume())); this._terminalService.setNativeDelegate({ diff --git a/src/vs/workbench/electron-sandbox/window.ts b/src/vs/workbench/electron-sandbox/window.ts index 2978c4157dbb40..5c15c2e0a269a5 100644 --- a/src/vs/workbench/electron-sandbox/window.ts +++ b/src/vs/workbench/electron-sandbox/window.ts @@ -180,36 +180,40 @@ export class NativeWindow extends Disposable { }); // Support openFiles event for existing and new files - ipcRenderer.on('vscode:openFiles', (event: unknown, request: IOpenFileRequest) => this.onOpenFiles(request)); + ipcRenderer.on('vscode:openFiles', (event: unknown, request: IOpenFileRequest) => { this.onOpenFiles(request); }); // Support addFolders event if we have a workspace opened - ipcRenderer.on('vscode:addFolders', (event: unknown, request: IAddFoldersRequest) => this.onAddFoldersRequest(request)); + ipcRenderer.on('vscode:addFolders', (event: unknown, request: IAddFoldersRequest) => { this.onAddFoldersRequest(request); }); // Message support - ipcRenderer.on('vscode:showInfoMessage', (event: unknown, message: string) => this.notificationService.info(message)); + ipcRenderer.on('vscode:showInfoMessage', (event: unknown, message: string) => { this.notificationService.info(message); }); // Shell Environment Issue Notifications - ipcRenderer.on('vscode:showResolveShellEnvError', (event: unknown, message: string) => this.notificationService.prompt( - Severity.Error, - message, - [{ - label: localize('learnMore', "Learn More"), - run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2149667') - }] - )); - - ipcRenderer.on('vscode:showCredentialsError', (event: unknown, message: string) => this.notificationService.prompt( - Severity.Error, - localize('keychainWriteError', "Writing login information to the keychain failed with error '{0}'.", message), - [{ - label: localize('troubleshooting', "Troubleshooting Guide"), - run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2190713') - }] - )); + ipcRenderer.on('vscode:showResolveShellEnvError', (event: unknown, message: string) => { + this.notificationService.prompt( + Severity.Error, + message, + [{ + label: localize('learnMore', "Learn More"), + run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2149667') + }] + ); + }); + + ipcRenderer.on('vscode:showCredentialsError', (event: unknown, message: string) => { + this.notificationService.prompt( + Severity.Error, + localize('keychainWriteError', "Writing login information to the keychain failed with error '{0}'.", message), + [{ + label: localize('troubleshooting', "Troubleshooting Guide"), + run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2190713') + }] + ); + }); // Fullscreen Events - ipcRenderer.on('vscode:enterFullScreen', async () => setFullscreen(true)); - ipcRenderer.on('vscode:leaveFullScreen', async () => setFullscreen(false)); + ipcRenderer.on('vscode:enterFullScreen', async () => { setFullscreen(true); }); + ipcRenderer.on('vscode:leaveFullScreen', async () => { setFullscreen(false); }); // Proxy Login Dialog ipcRenderer.on('vscode:openProxyAuthenticationDialog', async (event: unknown, payload: { authInfo: AuthInfo; username?: string; password?: string; replyChannel: string }) => {