Skip to content

Commit 2fd9a50

Browse files
test
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent 67db0cf commit 2fd9a50

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

build/scripts/entrypoint-volume.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ fi
112112
# Set the default path to the serverDataFolderName
113113
# into a persistent volume
114114
export VSCODE_AGENT_FOLDER=/checode/remote
115+
# Prevent bundled runtime LD_LIBRARY_PATH from leaking into integrated terminal shell env.
116+
export CHECODE_STRIP_LD_LIBRARY_PATH_FOR_SHELL_ENV=1
115117

116118
if [ -z "$VSCODE_NODEJS_RUNTIME_DIR" ]; then
117119
export VSCODE_NODEJS_RUNTIME_DIR="$(pwd)"

code/src/vs/platform/shell/node/shellEnv.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ import { IConfigurationService } from '../../configuration/common/configuration.
2020
import { clamp } from '../../../base/common/numbers.js';
2121

2222
let unixShellEnvPromise: Promise<typeof process.env> | undefined = undefined;
23+
const cheCodeLdLibPrefixes = new Set<string>([
24+
'/checode/checode-linux-libc/ubi8/ld_libs',
25+
'/checode/checode-linux-libc/ubi9/ld_libs',
26+
'/checode/checode-linux-musl/ld_libs'
27+
]);
28+
29+
function stripCheCodeLdLibraryPath(value: string | undefined): string | undefined {
30+
if (!value) {
31+
return undefined;
32+
}
33+
34+
const filtered = value
35+
.split(':')
36+
.map(entry => entry.trim())
37+
.filter(entry => entry.length > 0 && !cheCodeLdLibPrefixes.has(entry));
38+
39+
return filtered.length > 0 ? filtered.join(':') : undefined;
40+
}
2341

2442
/**
2543
* Resolves the shell environment by spawning a shell. This call will cache
@@ -105,16 +123,27 @@ async function doResolveUnixShellEnv(logService: ILogService, token: Cancellatio
105123

106124
const noAttach = process.env['ELECTRON_NO_ATTACH_CONSOLE'];
107125
logService.trace('getUnixShellEnvironment#noAttach', noAttach);
126+
const stripLdLibraryPath = process.env['CHECODE_STRIP_LD_LIBRARY_PATH_FOR_SHELL_ENV'] === '1';
108127

109128
const mark = generateUuid().replace(/-/g, '').substr(0, 12);
110129
const regex = new RegExp(mark + '({.*})' + mark);
111130

112-
const env = {
131+
const env: NodeJS.ProcessEnv = {
113132
...process.env,
114133
ELECTRON_RUN_AS_NODE: '1',
115134
ELECTRON_NO_ATTACH_CONSOLE: '1',
116135
VSCODE_RESOLVING_ENVIRONMENT: '1'
117136
};
137+
if (stripLdLibraryPath) {
138+
// Keep bundled runtime libs for server startup, but do not leak che-code-specific
139+
// runtime paths into the integrated terminal environment.
140+
const sanitizedLdLibraryPath = stripCheCodeLdLibraryPath(env['LD_LIBRARY_PATH']);
141+
if (sanitizedLdLibraryPath) {
142+
env['LD_LIBRARY_PATH'] = sanitizedLdLibraryPath;
143+
} else {
144+
delete env['LD_LIBRARY_PATH'];
145+
}
146+
}
118147

119148
logService.trace('getUnixShellEnvironment#env', env);
120149
const systemShellUnix = await getSystemShell(OS, env);
@@ -207,6 +236,14 @@ async function doResolveUnixShellEnv(logService: ILogService, token: Cancellatio
207236
}
208237

209238
delete env['VSCODE_RESOLVING_ENVIRONMENT'];
239+
if (stripLdLibraryPath) {
240+
const sanitizedLdLibraryPath = stripCheCodeLdLibraryPath(env['LD_LIBRARY_PATH']);
241+
if (sanitizedLdLibraryPath) {
242+
env['LD_LIBRARY_PATH'] = sanitizedLdLibraryPath;
243+
} else {
244+
delete env['LD_LIBRARY_PATH'];
245+
}
246+
}
210247

211248
// https://github.com/microsoft/vscode/issues/22593#issuecomment-336050758
212249
delete env['XDG_RUNTIME_DIR'];

0 commit comments

Comments
 (0)