Skip to content
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

Fix potential nil panics in ee/desktop/runner detected by nilaway #1694

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions ee/desktop/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,11 @@ func (r *DesktopUsersProcessesRunner) spawnForUser(ctx context.Context, uid stri
traces.SetError(span, fmt.Errorf("running desktop command as user: %w", err))
return fmt.Errorf("running desktop command as user: %w", err)
}
// Extra nil check to ensure we can access cmd.Process.Pid safely later
if cmd.Process == nil {
traces.SetError(span, fmt.Errorf("starting desktop command: %w", err))
return fmt.Errorf("starting desktop command: %w", err)
}

span.AddEvent("command_started")

Expand Down
2 changes: 1 addition & 1 deletion ee/desktop/runner/runner_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (r *DesktopUsersProcessesRunner) runAsUser(ctx context.Context, uid string,
}

runningUser, err := user.LookupId(uid)
if err != nil {
if err != nil || runningUser == nil {
return fmt.Errorf("looking up user with uid %s: %w", uid, err)
}

Expand Down
2 changes: 1 addition & 1 deletion ee/desktop/runner/runner_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (r *DesktopUsersProcessesRunner) runAsUser(ctx context.Context, uid string,
}

runningUser, err := user.LookupId(uid)
if err != nil {
if err != nil || runningUser == nil {
return fmt.Errorf("looking up user with uid %s: %w", uid, err)
}

Expand Down
2 changes: 1 addition & 1 deletion ee/desktop/runner/runner_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (r *DesktopUsersProcessesRunner) runAsUser(ctx context.Context, uid string,
defer span.End()

explorerProc, err := consoleuser.ExplorerProcess(ctx, uid)
if err != nil {
if err != nil || explorerProc == nil {
return fmt.Errorf("getting user explorer process: %w", err)
}

Expand Down
Loading