Skip to content

Commit 3793256

Browse files
committed
fix(cli/ssh): prevent stdin/stdout reads/writes in stdio mode
Fixes #11530
1 parent f2aef07 commit 3793256

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

cli/ssh.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func (r *RootCmd) ssh() *clibase.Cmd {
8787
}
8888
}()
8989

90+
// In stdio mode, we can't allow any writes to stdin or stdout
91+
// because they are used by the SSH protocol.
92+
stdioReader, stdioWriter := inv.Stdin, inv.Stdout
93+
if stdio {
94+
inv.Stdin = stdioWarnReader{inv.Logger}
95+
inv.Stdout = inv.Stderr
96+
}
97+
9098
// This WaitGroup solves for a race condition where we were logging
9199
// while closing the log file in a defer. It probably solves
92100
// others too.
@@ -234,7 +242,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
234242
if err != nil {
235243
return xerrors.Errorf("connect SSH: %w", err)
236244
}
237-
copier := newRawSSHCopier(logger, rawSSH, inv.Stdin, inv.Stdout)
245+
copier := newRawSSHCopier(logger, rawSSH, stdioReader, stdioWriter)
238246
if err = stack.push("rawSSHCopier", copier); err != nil {
239247
return err
240248
}
@@ -987,3 +995,12 @@ func sshDisableAutostartOption(src *clibase.Bool) clibase.Option {
987995
Default: "false",
988996
}
989997
}
998+
999+
type stdioWarnReader struct {
1000+
l slog.Logger
1001+
}
1002+
1003+
func (r stdioWarnReader) Read(p []byte) (n int, err error) {
1004+
r.l.Warn(context.Background(), "reading from stdin in stdio mode is not supported")
1005+
return 0, io.EOF
1006+
}

0 commit comments

Comments
 (0)