ssh -t exec path concatenates the command unquoted — GNU-style -c shells lose all but the first word
評価
調査の方向性
The bug is in the pty branch of contrib/win32/win32compat/w32-doexec.c, where the command is concatenated unquoted after the shell's -c. Study the non-pty branch just below it and how build_exec_command escapes quotes/backslashes, then mirror that escaping in the pty path. Repro with a Git Bash DefaultShell and ssh -tt host 'sleep 30'; done means multi-word commands run identically with and without -t, including commands containing embedded quotes.
索引モデルが issue の本文から書いたものです。
説明
"OpenSSH for Windows" version: 9.5p1 (in-box Optional Feature)
Server / Client OS: Windows 10 19045
What is failing
When a pty is allocated (ssh -t), do_exec_windows builds the shell
command line by plain concatenation in contrib/win32/win32compat/w32-doexec.c:
// pty path
strcpy_s(pty_cmd, len, shell); // "\"<shell path>\""
strcat_s(pty_cmd, len, " ");
strcat_s(pty_cmd, len, shell_command_option_local); // "-c"
strcat_s(pty_cmd, len, " ");
strcat_s(pty_cmd, len, command); // NOT quoted
This produces "C:\shell.exe" -c echo a b. Any shell whose -c takes a
single operand (GNU semantics — bash, and other bash-compatible shells)
then runs echo with a b demoted to $0/$1: the command silently
truncates to its first word.
The non-pty path immediately below does quote:
sprintf_s(posix_cmd_input, len, "%s %s \"%s\"", shell, option, exec_command);
Repro
Set a GNU-style shell as DefaultShell (e.g. Git Bash bash.exe or
Niubash niu.exe) with DefaultShellCommandOption = -c, then:
ssh -tt host 'whoami' → works (single word)
ssh -tt host 'sleep 30' → "sleep: missing operand" (30 lost)
ssh -tt host 'printf ok123' → "printf: usage: ..." (ok123 lost)
ssh -tt host 'echo x > f.txt' → bare echo; redirect never reaches the shell
ssh -tt host 'cmd /c echo x' → an interactive cmd prompt (args dropped)
The same commands work fine without -t, confirming the quoting
discrepancy between the two branches. cmd.exe and powershell.exe are not
affected because their /c/-c consume the rest of the command line —
which is presumably why this has gone unnoticed.
Expected
ssh -tt host 'sleep 30' runs sleep 30, same as without a pty.
Suggested fix
Quote the command operand in the pty branch (with proper
CommandLineToArgvW escaping for embedded quotes/backslashes), e.g.
append "%s" — noting that merely wrapping in quotes is not sufficient
for commands that already contain quotes; the escaping rules used by
build_exec_command/the non-pty path should be mirrored.
- 主要言語
- 言語のデータがありません
- スター
- 8.3k
- フォーク
- 822
- 平均マージ
- 7分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PowerShell/Win32-OpenSSH のほかの issue
-
Area-ssh-agent Issue-Upstream Parity
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
PowerShell/Win32-OpenSSH#2458 · コメント 1 件 · リアクション 1 件 ·
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
PowerShell/Win32-OpenSSH#2479 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
PowerShell/Win32-OpenSSH#2476 · リアクション 1 件 ·
-
10.4.0.0p1-Preview: SSH sessions no longer get the user's PATH (HKCU\Environment), only the machine PATH対応中かも @tgauth が 3 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 57/100
PowerShell/Win32-OpenSSH#2474 · コメント 3 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
PowerShell/Win32-OpenSSH#2472 · コメント 1 件 · リアクション 1 件 ·
PowerShell/Win32-OpenSSH の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aristocratos/btop#1945 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
boykopovar/AnyPS5#11291 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
stac-utils/stac-fastapi-elasticsearch-opensearch#965 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 71/100
Automattic/blocks-engine#3438 ·
メンテナーはふだん 1 日以内に返信
-
bug help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Tencent/teamai-cli#1397 ·
メンテナーはふだん 1 日以内に返信