jesseduffield / jesseduffield/lazygit

Potential nil dereference in worktree porcelain parser

Open
#5,372 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
82.4k
Forks
3k
Avg merge
2d 18h
Merged PRs (30d)
19

Description

Hi,

In `pkg/commands/git_commands/worktree_loader.go`, the porcelain output parser accesses `current.Head` and `current.Branch` without checking if `current` is nil.

`current` starts as nil and is also set to nil after encountering a "bare" line. If `git worktree list --porcelain` produces unexpected output (e.g., a "HEAD" or "branch" line without a preceding "worktree" line — which can happen with corrupted git state or manual worktree directory manipulation), this will panic.

This might be related to some of the worktree crashes reported in #5266.

A simple nil check before each access would make the parser more defensive.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.