Skip to content

Commit a0cd34c

Browse files
committed
Fixes microsoft#134177: unset LD_PRELOAD on Linux and consolidate code
1 parent c0001d7 commit a0cd34c

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

src/vs/base/node/processes.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,35 @@ function terminateProcess(process: cp.ChildProcess, cwd?: string): Promise<Termi
8787
return Promise.resolve({ success: true });
8888
}
8989

90+
/**
91+
* Remove dangerous environment variables that have caused crashes
92+
* in forked processes (i.e. in ELECTRON_RUN_AS_NODE processes)
93+
*
94+
* @param env The env object to change
95+
*/
96+
export function removeDangerousEnvVariables(env: NodeJS.ProcessEnv | undefined): void {
97+
if (!env) {
98+
return;
99+
}
100+
101+
// Unset `DEBUG`, as an invalid value might lead to process crashes
102+
// See https://github.com/microsoft/vscode/issues/130072
103+
delete env['DEBUG'];
104+
105+
if (Platform.isMacintosh) {
106+
// Unset `DYLD_LIBRARY_PATH`, as it leads to process crashes
107+
// See https://github.com/microsoft/vscode/issues/104525
108+
// See https://github.com/microsoft/vscode/issues/105848
109+
delete env['DYLD_LIBRARY_PATH'];
110+
}
111+
112+
if (Platform.isLinux) {
113+
// Unset `LD_PRELOAD`, as it might lead to process crashes
114+
// See https://github.com/microsoft/vscode/issues/134177
115+
delete env['LD_PRELOAD'];
116+
}
117+
}
118+
90119
export function getWindowsShell(env = process.env as Platform.IProcessEnvironment): string {
91120
return env['comspec'] || 'cmd.exe';
92121
}

src/vs/base/parts/ipc/node/ipc.cp.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import * as errors from 'vs/base/common/errors';
1212
import { Emitter, Event } from 'vs/base/common/event';
1313
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
1414
import { deepClone } from 'vs/base/common/objects';
15-
import { isMacintosh } from 'vs/base/common/platform';
16-
import { createQueuedSender } from 'vs/base/node/processes';
15+
import { createQueuedSender, removeDangerousEnvVariables } from 'vs/base/node/processes';
1716
import { ChannelClient as IPCClient, ChannelServer as IPCServer, IChannel, IChannelClient } from 'vs/base/parts/ipc/common/ipc';
1817

1918
/**
@@ -202,11 +201,7 @@ export class Client implements IChannelClient, IDisposable {
202201
forkOpts.execArgv = process.execArgv.filter(a => !/^--inspect(-brk)?=/.test(a)); // remove
203202
}
204203

205-
if (isMacintosh && forkOpts.env) {
206-
// Unset `DYLD_LIBRARY_PATH`, as it leads to process crashes
207-
// See https://github.com/microsoft/vscode/issues/105848
208-
delete forkOpts.env['DYLD_LIBRARY_PATH'];
209-
}
204+
removeDangerousEnvVariables(forkOpts.env);
210205

211206
this.child = fork(this.modulePath, args, forkOpts);
212207

src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerMain.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
1010
import { Event, Emitter } from 'vs/base/common/event';
1111
import { Disposable } from 'vs/base/common/lifecycle';
1212
import { deepClone } from 'vs/base/common/objects';
13-
import { isMacintosh } from 'vs/base/common/platform';
13+
import { removeDangerousEnvVariables } from 'vs/base/node/processes';
1414
import { ISharedProcessWorkerConfiguration } from 'vs/platform/sharedProcess/common/sharedProcessWorkerService';
1515
import { SharedProcessWorkerMessages, ISharedProcessToWorkerMessage, ISharedProcessWorkerEnvironment } from 'vs/platform/sharedProcess/electron-browser/sharedProcessWorker';
1616

@@ -140,15 +140,7 @@ class SharedProcessWorkerProcess extends Disposable {
140140
VSCODE_PARENT_PID: String(process.pid)
141141
};
142142

143-
// Unset `DEBUG`, as an invalid value might lead to crashes
144-
// See https://github.com/microsoft/vscode/issues/130072
145-
delete env['DEBUG'];
146-
147-
if (isMacintosh) {
148-
// Unset `DYLD_LIBRARY_PATH`, as it leads to extension host crashes
149-
// See https://github.com/microsoft/vscode/issues/104525
150-
delete env['DYLD_LIBRARY_PATH'];
151-
}
143+
removeDangerousEnvVariables(env);
152144

153145
return env;
154146
}

src/vs/workbench/services/extensions/electron-browser/localProcessExtensionHost.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { IShellEnvironmentService } from 'vs/workbench/services/environment/elec
4848
import { IExtensionHostProcessOptions, IExtensionHostStarter } from 'vs/platform/extensions/common/extensionHostStarter';
4949
import { SerializedError } from 'vs/base/common/errors';
5050
import { StopWatch } from 'vs/base/common/stopwatch';
51+
import { removeDangerousEnvVariables } from 'vs/base/node/processes';
5152

5253
export interface ILocalProcessExtensionHostInitData {
5354
readonly autoStart: boolean;
@@ -239,15 +240,7 @@ export class LocalProcessExtensionHost implements IExtensionHost {
239240
objects.mixin(env, this._environmentService.debugExtensionHost.env);
240241
}
241242

242-
// Unset `DEBUG`, as an invalid value might lead to extension host crashes
243-
// See https://github.com/microsoft/vscode/issues/130072
244-
delete env['DEBUG'];
245-
246-
if (platform.isMacintosh) {
247-
// Unset `DYLD_LIBRARY_PATH`, as it leads to extension host crashes
248-
// See https://github.com/microsoft/vscode/issues/104525
249-
delete env['DYLD_LIBRARY_PATH'];
250-
}
243+
removeDangerousEnvVariables(env);
251244

252245
if (this._isExtensionDevHost) {
253246
// Unset `VSCODE_CODE_CACHE_PATH` when developing extensions because it might

0 commit comments

Comments
 (0)