Skip to content

shellIntegration-bash leaks cmd variable into the environment #205131

@AndrewDDavis

Description

@AndrewDDavis

Type: Bug

Steps to reproduce:

  1. set a non-empty PROMPT_COMMAND string or array in ~/.bashrc
  2. start a new terminal in vs-code
  3. run declare -p cmd, observe that this variable has a value

Details:
On l. 278 of shellIntegration-bash.sh, a loop is run as for cmd in ..., but cmd has not been declared local to the function. As a result, the shell environment retains the cmd variable containing the last element of the original PROMPT_COMMAND array.

Fix:
Line 278 could be prepended with a local cmd declaration so that the variable doesn't leak out of the function scope.

__vsc_prompt_cmd_original() {
__vsc_status="$?"
__vsc_restore_exit_code "${__vsc_status}"
# Evaluate the original PROMPT_COMMAND similarly to how bash would normally
# See https://unix.stackexchange.com/a/672843 for technique
for cmd in "${__vsc_original_prompt_command[@]}"; do
eval "${cmd:-}"
done
__vsc_precmd
}

VS Code version: Code 1.86.1 (31c37ee, 2024-02-07T09:07:19.849Z)
OS version: Linux x64 6.1.60-08594-g03a802b9a072
Modes: Unsupported

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz (8 x 2419)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 0, 0, 0
Memory (System) 6.42GB (4.80GB free)
Process Argv --unity-launch --crash-reporter-id 754871d2-cdd9-4dde-a93b-9c06b82d2c68
Screen Reader no
VM 100%
DESKTOP_SESSION undefined
XDG_CURRENT_DESKTOP X-Generic
XDG_SESSION_DESKTOP undefined
XDG_SESSION_TYPE undefined
Extensions (26)
Extension Author (truncated) Version
increment-selection alb 0.2.0
Bookmarks ale 13.4.2
insert-unicode bru 0.15.1
systemd-unit-file coo 1.0.6
markdown-table-prettify dar 3.6.0
vscode-edit-csv jan 0.8.3
markdown-shortcuts mdi 0.12.0
debugpy ms- 2024.0.0
isort ms- 2023.10.1
python ms- 2024.0.1
vscode-pylance ms- 2024.2.1
jupyter ms- 2024.1.1
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.0.17
vscode-jupyter-cell-tags ms- 0.1.8
vscode-jupyter-slideshow ms- 0.1.5
adwaita-theme pio 1.1.0
regex-text-gen rio 0.14.0
snippets-ranger rob 1.8.0
edit-with-shell ryu 1.3.0
markdown-preview-enhanced shd 0.8.11
rewrap stk 1.16.3
system-viewer sys 1.1.1
pdf tom 1.2.2
change-case wma 1.0.0
markdown-all-in-one yzh 3.6.2

(1 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:30899288
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
pythontbext0:30879054
accentitlementsc:30887149
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
edj9j583:30958191
3ef8e399:30962115
bg6jg535:30958357
ccp2r3:30958157

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable buginsiders-releasedPatch has been released in VS Code Insidersterminal-shell-bashAn issue in the terminal specific to bash, including shell integrationterminal-shell-integrationShell integration infrastructure, command decorations, etc.verifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions