Skip to content

Commit 3ca6f1f

Browse files
authored
fix: Prevent nil pointer deref in reconnectingPTY (#3871)
Related #3870
1 parent 1a5d3ea commit 3ca6f1f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

agent/agent.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -728,26 +728,28 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, msg reconnectingPTYIn
728728
if ok {
729729
rpty, ok = rawRPTY.(*reconnectingPTY)
730730
if !ok {
731-
a.logger.Warn(ctx, "found invalid type in reconnecting pty map", slog.F("id", msg.ID))
731+
a.logger.Error(ctx, "found invalid type in reconnecting pty map", slog.F("id", msg.ID))
732+
return
732733
}
733734
} else {
734735
// Empty command will default to the users shell!
735736
cmd, err := a.createCommand(ctx, msg.Command, nil)
736737
if err != nil {
737-
a.logger.Warn(ctx, "create reconnecting pty command", slog.Error(err))
738+
a.logger.Error(ctx, "create reconnecting pty command", slog.Error(err))
738739
return
739740
}
740741
cmd.Env = append(cmd.Env, "TERM=xterm-256color")
741742

742-
ptty, process, err := pty.Start(cmd)
743+
// Default to buffer 64KiB.
744+
circularBuffer, err := circbuf.NewBuffer(64 << 10)
743745
if err != nil {
744-
a.logger.Warn(ctx, "start reconnecting pty command", slog.F("id", msg.ID))
746+
a.logger.Error(ctx, "create circular buffer", slog.Error(err))
747+
return
745748
}
746749

747-
// Default to buffer 64KiB.
748-
circularBuffer, err := circbuf.NewBuffer(64 << 10)
750+
ptty, process, err := pty.Start(cmd)
749751
if err != nil {
750-
a.logger.Warn(ctx, "create circular buffer", slog.Error(err))
752+
a.logger.Error(ctx, "start reconnecting pty command", slog.F("id", msg.ID))
751753
return
752754
}
753755

0 commit comments

Comments
 (0)