@@ -20,6 +20,24 @@ import { IConfigurationService } from '../../configuration/common/configuration.
2020import { clamp } from '../../../base/common/numbers.js' ;
2121
2222let 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