Skip to content

Spawn .bat/.cmd DebugAdapterExecutables with shell=true - #224320

Merged
roblourens merged 5 commits into
release/1.92from
roblou/batDAspawn
Jul 30, 2024
Merged

roblourens merged 5 commits into
release/1.92from
roblou/batDAspawn

Conversation

@roblourens

@roblourens roblourens commented Jul 30, 2024 •

Copy link
Copy Markdown
Member

Fix #224184

  • Spawn can use powershell if the user has set COMSPEC to point at powershell, but I don't think this is that common?
  • I'm unsure about escaping the args, because I think that in the previous node version, they would have had to be escaped already, but I'll check
  • In any case, the DAs that pass the if check would be broken anyway in this release.

@roblourens roblourens added this to the July 2024 milestone Jul 30, 2024
// https://github.com/microsoft/vscode/issues/224184
spawnOptions.shell = true;
spawnCommand = `"${command}"`;
spawnArgs = args.map(a => `"${a}"`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any args contain " do those need escaping?

(mine don't, and hopefully others don't, but who knows?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like they do 😞

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC things like "<" can cause issues too (see https://ss64.com/nt/syntax-esc.html). In Dart-Code I have this escape function:

https://github.com/Dart-Code/Dart-Code/blob/d1894e79c99360438d509922e5b8ff391ecdbcf0/src/shared/processes.ts#L29

I don't know if it's reliable (particularly if you changed COMSPEC to PoSh, but hopefully nobody is doing that 😄) or how likely it is in the debug adapter executable (it came up for me because test names can be passed as args to some processes and that's a shared escape function).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you already escaping any args that go to the DebugAdapterExecutable? Or is it a fixed set of args?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not escaping anything for DebugAdapterExecutable because it's not usually required (the function above is used in the places where we are using shell:true to spawn our own processes).

Or is it a fixed set of args?

Yep, for the place that will come through DebugAdapterExecutable our args are fixed (well, they're dynamic, but from a small set which is basically ["debug_adapter", "--test", "--no-dds"]). There are a few small exceptions (where you might pass a full path), but they're generally just for me (or other contributors to the debug adapter) that are running from source.

(TL;DR; simple escaping such as only putting quotes around them is definitely good enough for me, and the comments above were just general comments about being strict in case others are doing weirder things)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This level of escaping seems to be fine, including for characters like >, although cmd.exe escaping is obviously extremely weird.

Did you test that this works for your scenarios Danny Tuppeny (@DanTup)?

Comment thread src/vs/workbench/contrib/debug/node/debugAdapter.ts
@DanTup

Danny Tuppeny (DanTup) commented Jul 30, 2024 •

Copy link
Copy Markdown
Contributor

(btw, typo in title/ commit "with spawn=true" should be "with shell=true")

@roblourens roblourens changed the title Spawn .bat/.cmd DebugAdapterExecutables with spawn=true Spawn .bat/.cmd DebugAdapterExecutables with shell=true Jul 30, 2024
@roblourens
roblourens merged commit 3bb1578 into release/1.92 Jul 30, 2024
@roblourens
roblourens deleted the roblou/batDAspawn branch July 30, 2024 23:40
roblourens added a commit that referenced this pull request Jul 30, 2024
* Spawn .bat DAs with shell=true

* Also escape args

* And .cmd

* escape argument properly

* Don't escape \
roblourens added a commit that referenced this pull request Jul 30, 2024
Spawn .bat/.cmd DebugAdapterExecutables with shell=true (#224320)

* Spawn .bat DAs with shell=true

* Also escape args

* And .cmd

* escape argument properly

* Don't escape \
@DanTup

Danny Tuppeny (DanTup) commented Jul 31, 2024 •

Copy link
Copy Markdown
Contributor

I just checked out 3bb1578 (branch release/1.92) and tested with my workaround reverted, and the debug adapter is correctly spawned from the .bat and works as expected (both with and without the common args we use).

Dart Code extension: 3.93.0-dev.reverted
App: Code - OSS Dev
Version: win 1.92.0

[10:13:39 AM] [General] [Info] Running SDK DAP Dart VM in undefined: C:\Dev\Google\Flutter\Flutter main\bin\flutter.bat debug_adapter and options {"env":{"FLUTTER_HOST":"VSCode","PUB_ENVIRONMENT":"vscode.dart-code","FLUTTER_ROOT":"C:\\Dev\\Google\\Flutter\\Flutter main"}}
[10:13:39 AM] [DAP] [Info] Starting debug session 79f96753-a0c4-44f5-9e6c-bdb6025359a9
[10:13:39 AM] [DAP] [Info] ==> {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Code - OSS Dev","adapterID":"dart","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true,"supportsMemoryEvent":true,"supportsStartDebuggingRequest":true,"supportsDartUris":true},"type":"request","seq":1}
[10:13:39 AM] [DAP] [Info] <== {"seq":1,"type":"response","body":{"exceptionBreakpointFilters":[{"default":false,"filter":"All","label":"All Exceptions"},{"default":true,"filter":"Unhandled","label":"Uncaught Exceptions"}],"supportsClipboardContext":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDelayedStackTraceLoading":true,"supportsEvaluateForHovers":true,"supportsLogPoints":true,"supportsRestartFrame":true,"supportsRestartRequest":false,"supportsTerminateRequest":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"success":true}
[10:13:39 AM] [DAP] [Info] <== {"seq":2,"type":"event","body":{},"event":"initialized"}

Thank you for this, I really appreciate it - it will have saved us a lot of pain and duplicate GH issues 😄

Does the release branch automatically get merged back to main periodically, or is there something more to do for the subsequent release? nm, just saw #224350 :-)

@roblourens

Copy link
Copy Markdown
Member Author

Thanks!

mustard (mustard-mh) pushed a commit to gitpod-io/openvscode-server that referenced this pull request Sep 2, 2024
…4320)

* Spawn .bat DAs with shell=true

* Also escape args

* And .cmd

* escape argument properly

* Don't escape \
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants