Profile matching doesn't work with paths containing unquoted whitespace #16609

Open
opened 2026-01-31 05:17:13 +00:00 by claunia · 0 comments
Owner

Originally created by @lhecker on GitHub (Feb 3, 2022).

Windows Terminal version

1.12.2922.0

Steps to reproduce

Issue 1 - paths with more than 1 whitespace

This code:
e064c15675/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp (L756-L757)

When the loop is executed a second time (meaning: paths having more than one whitespace), argv[2][-1] should be set to whitespace, since argv[1][-1] still refers to the old whitespace between the first two arguments.

Due to this, the path

C:\foo - bar\baz.exe 60 120

is resolved to

"C:\\foo - bar\\baz.exe 60 120"

when it should be

"C:\\foo - bar\\baz.exe\060\0120"

Since SearchPathW will never have been given a valid path, path resolution will fail entirely and the input path be returned unmodified.

Issue 2 - path resolution picks the first matching directory

This code:
e064c15675/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp (L717-L719)

SearchPathW resolves to any path including directories and not just to file paths.

If you have

  • a directory at C:\foo
  • an executable at C:\foo - bar\baz.exe

then the path

C:\foo - bar\baz.exe 60 120

will be resolved to

"C:\\foo\0-\0bar\\baz.exe\060\0120"
        ^^ ^^

when it should be

"C:\\foo - bar\\baz.exe\060\0120"

Profile matching will still succeed since the path of the handed off process is normalized the exact same way. However matching will be buggy, since it's ambigious with any path that actually has arguments in these places.

Originally created by @lhecker on GitHub (Feb 3, 2022). ## Windows Terminal version 1.12.2922.0 ## Steps to reproduce ### Issue 1 - paths with more than 1 whitespace This code: https://github.com/microsoft/terminal/blob/e064c1567548f098233b7a2d1101cb5201dec049/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp#L756-L757 When the loop is executed a second time (meaning: paths having more than one whitespace), `argv[2][-1]` should be set to whitespace, since `argv[1][-1]` still refers to the old whitespace between the first two arguments. Due to this, the path ``` C:\foo - bar\baz.exe 60 120 ``` is resolved to ```cpp "C:\\foo - bar\\baz.exe 60 120" ``` when it should be ```cpp "C:\\foo - bar\\baz.exe\060\0120" ``` Since `SearchPathW` will never have been given a valid path, path resolution will fail entirely and the input path be returned unmodified. ### Issue 2 - path resolution picks the first matching directory This code: https://github.com/microsoft/terminal/blob/e064c1567548f098233b7a2d1101cb5201dec049/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp#L717-L719 `SearchPathW` resolves to any path including directories and not just to file paths. If you have * a directory at `C:\foo` * an executable at `C:\foo - bar\baz.exe` then the path ``` C:\foo - bar\baz.exe 60 120 ``` will be resolved to ```cpp "C:\\foo\0-\0bar\\baz.exe\060\0120" ^^ ^^ ``` when it should be ```cpp "C:\\foo - bar\\baz.exe\060\0120" ``` Profile matching will still succeed since the path of the handed off process is normalized the exact same way. However matching will be buggy, since it's ambigious with any path that actually has arguments in these places.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16609