From 59f1e9ebd11ef4fcf7fb6716ea9088281d01cec5 Mon Sep 17 00:00:00 2001 From: "Bob Brown (DEVDIV)" Date: Mon, 11 Apr 2022 13:38:55 -0700 Subject: [PATCH] Remove problematic environment variables from the debugger environment --- CHANGELOG.md | 1 + src/debugger.ts | 4 +--- src/util.ts | 3 ++- test/unit-tests/debugger.test.ts | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/unit-tests/debugger.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index c194aa7b8e..c9e6766b7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Bug Fixes: - Update terminal's environment variables when the kit is changed. [#2364](https://github.com/microsoft/vscode-cmake-tools/issues/2364) - Add timeouts for compiler scanning. [#1289](https://github.com/microsoft/vscode-cmake-tools/issues/1289) - Fix schema validation for presets version 4. [#2490](https://github.com/microsoft/vscode-cmake-tools/issues/2490) +- Remove problematic environment variables from the debugger environment. [#2442](https://github.com/microsoft/vscode-cmake-tools/issues/2442) ## 1.10.5 Bug Fixes: diff --git a/src/debugger.ts b/src/debugger.ts index 554367f302..fc4c6a0211 100644 --- a/src/debugger.ts +++ b/src/debugger.ts @@ -162,9 +162,7 @@ function searchForCompilerPathInCache(cache: CMakeCache): string | null { return null; } -export async function getDebugConfigurationFromCache(cache: CMakeCache, target: ExecutableTarget, platform: string, - modeOverride?: MIModes, debuggerPathOverride?: string): - Promise { +export async function getDebugConfigurationFromCache(cache: CMakeCache, target: ExecutableTarget, platform: string, modeOverride?: MIModes, debuggerPathOverride?: string): Promise { const entry = cache.get('CMAKE_LINKER'); if (entry !== null) { const linker = entry.value as string; diff --git a/src/util.ts b/src/util.ts index 1ed99eb0ef..5e1562aba9 100644 --- a/src/util.ts +++ b/src/util.ts @@ -376,9 +376,10 @@ export function makeDebuggerEnvironmentVars(env?: Environment): DebuggerEnvironm if (!env) { return []; } + const filter: RegExp = /\$\{.+?\}/; // Disallow env variables that have variable expansion values const converted_env: DebuggerEnvironmentVariable[] = []; for (const [key, value] of Object.entries(env)) { - if (value !== undefined) { + if (value !== undefined && !value.match(filter)) { converted_env.push({ name: key, value diff --git a/test/unit-tests/debugger.test.ts b/test/unit-tests/debugger.test.ts new file mode 100644 index 0000000000..1fcb536310 --- /dev/null +++ b/test/unit-tests/debugger.test.ts @@ -0,0 +1,16 @@ +import { fromDebuggerEnvironmentVars, makeDebuggerEnvironmentVars } from "@cmt/util"; +import { expect } from "@test/util"; + +suite('debugger tests', () => { + test('No variable expansion env vars', () => { + const env: {[key: string]: string} = {}; + env['foo'] = 'bar'; + env['other'] = '${hey'; + env['BASH_FUNC_which%%'] = '() { ( alias;\n eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot \"$@\"\n}'; + env['BASH_FUNC_module()'] = '() { eval $($LMOD_CMD bash "$@") && eval $(${LMOD_SETTARG_CMD:-:} -s sh'; + + const debugEnv = fromDebuggerEnvironmentVars(makeDebuggerEnvironmentVars(env)); + expect(debugEnv).to.contain.keys('foo', 'other'); + expect(debugEnv).to.not.contain.keys('BASH_FUNC_which%%', 'BASH_FUNC_module()'); + }); +});