Commit 34a6147
committed
bisect: ensure head is non-NULL before using it
bisect_start() calls refs_resolve_ref_unsafe() to resolve HEAD.
When this returns NULL (e.g., HEAD does not exist as a proper
ref), the code falls back to repo_get_oid("HEAD") to try to
resolve the OID directly. If that succeeds, execution continues
with head still set to NULL.
Later, at line 838, head is passed to repo_get_oid() and
starts_with(), both of which dereference the NULL pointer.
The scenario: refs_resolve_ref_unsafe returns NULL but
repo_get_oid succeeds. This can happen when HEAD is a detached
bare OID that the ref backend cannot resolve symbolically (a
potential edge case with the reftable backend) but the OID itself
is valid. In this case, the bisect-start file does not yet exist
(this is a fresh "git bisect start"), so the else branch at line
836 is taken with the NULL head.
Set head to "HEAD" as a fallback when refs_resolve_ref_unsafe
fails but the OID resolves. The subsequent code at line 838 will
then take the first branch (repo_get_oid succeeds, head does not
start with "refs/heads/") and record the OID hex as the start
point, which is the correct behavior for a detached HEAD.
Pointed out by Coverity.
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>1 parent b7566f0 commit 34a6147
1 file changed
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
808 | 808 | | |
809 | 809 | | |
810 | 810 | | |
811 | | - | |
| 811 | + | |
812 | 812 | | |
813 | 813 | | |
| 814 | + | |
| 815 | + | |
814 | 816 | | |
815 | 817 | | |
816 | 818 | | |
| |||
0 commit comments