Skip to content

fix(cli/ssh): prevent reads/writes to stdin/stdout in stdio mode #12045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
missed some names
  • Loading branch information
mafredri committed Feb 7, 2024
commit 6df02c1bb434e7ffbfd79c0c82f1cdecd6e9d825
14 changes: 7 additions & 7 deletions cli/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ func TestSSH(t *testing.T) {
// A[ProxyCommand] --> B[captureProxyCommandStdoutW]
// B --> C[captureProxyCommandStdoutR]
// C --> VA[Validate output]
// C --> D[proxyCommandOutputW]
// D --> E[proxyCommandOutputR]
// C --> D[proxyCommandStdoutW]
// D --> E[proxyCommandStdoutR]
// E --> F[SSH Client]
proxyCommandOutputR, proxyCommandOutputW := io.Pipe()
proxyCommandStdoutR, proxyCommandStdoutW := io.Pipe()
captureProxyCommandStdoutR, captureProxyCommandStdoutW := io.Pipe()
closePipes := func() {
for _, c := range []io.Closer{clientStdinR, clientStdinW, proxyCommandOutputR, proxyCommandOutputW, captureProxyCommandStdoutR, captureProxyCommandStdoutW} {
for _, c := range []io.Closer{clientStdinR, clientStdinW, proxyCommandStdoutR, proxyCommandStdoutW, captureProxyCommandStdoutR, captureProxyCommandStdoutW} {
_ = c.Close()
}
}
Expand Down Expand Up @@ -427,11 +427,11 @@ func TestSSH(t *testing.T) {
}
})
tGo(t, func() {
defer proxyCommandOutputW.Close()
defer proxyCommandStdoutW.Close()

// Range closed by above goroutine.
for b := range proxyCommandOutputBuf {
_, err := proxyCommandOutputW.Write([]byte{b})
_, err := proxyCommandStdoutW.Write([]byte{b})
if err != nil {
if errors.Is(err, io.ErrClosedPipe) {
return
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestSSH(t *testing.T) {
})

conn, channels, requests, err := ssh.NewClientConn(&stdioConn{
Reader: proxyCommandOutputR,
Reader: proxyCommandStdoutR,
Writer: clientStdinW,
}, "", &ssh.ClientConfig{
// #nosec
Expand Down