Skip to content

fix: Prevent nil pointer deref in reconnectingPTY #3871

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 1 commit into from
Sep 5, 2022
Merged
Changes from all commits
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
16 changes: 9 additions & 7 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,26 +728,28 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, msg reconnectingPTYIn
if ok {
rpty, ok = rawRPTY.(*reconnectingPTY)
if !ok {
a.logger.Warn(ctx, "found invalid type in reconnecting pty map", slog.F("id", msg.ID))
a.logger.Error(ctx, "found invalid type in reconnecting pty map", slog.F("id", msg.ID))
return
}
} else {
// Empty command will default to the users shell!
cmd, err := a.createCommand(ctx, msg.Command, nil)
if err != nil {
a.logger.Warn(ctx, "create reconnecting pty command", slog.Error(err))
a.logger.Error(ctx, "create reconnecting pty command", slog.Error(err))
return
}
cmd.Env = append(cmd.Env, "TERM=xterm-256color")

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

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

Expand Down