Skip to content

Commit 23350e9

Browse files
hq0101andydotxyz
authored andcommitted
Fix nil pointer dereference on SSH session closure in Terminal.run
Added a nil check for `t.cmd` before invoking `t.cmd.Wait()` in the terminal's run loop. This resolves the panic caused by closing the SSH session (via t.Exit() or session.Close()) when `t.cmd` is not initialized, ensuring graceful termination of the terminal.
1 parent fe1ab53 commit 23350e9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

term.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ func (t *Terminal) run() {
306306
for {
307307
num, err := t.out.Read(buf)
308308
if err != nil {
309-
// wait for cmd (shell) to exit, populates ProcessState.ExitCode
310-
t.cmd.Wait()
309+
if t.cmd != nil {
310+
// wait for cmd (shell) to exit, populates ProcessState.ExitCode
311+
t.cmd.Wait()
312+
}
311313
// this is the pre-go 1.13 way to check for the read failing (terminal closed)
312314
if err.Error() == "EOF" {
313315
break // term exit on macOS

0 commit comments

Comments
 (0)