Skip to content

Commit 428a3a0

Browse files
committed
bisect: ensure non-NULL head before using it
When `refs_resolve_ref_unsafe()` is called to resolve HEAD, and 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, that variable is passed to `repo_get_oid()` and `starts_with()`, both of which would dereference the NULL pointer. The scenario "`refs_resolve_ref_unsafe()` returns NULL but `repo_get_oid()` succeeds" 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 is taken with the NULL `head`. Simply assign "HEAD" to `head` as a fallback to address this. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 0b27860 commit 428a3a0

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

builtin/bisect.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,11 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
811811
*/
812812
head = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
813813
"HEAD", 0, &head_oid, &flags);
814-
if (!head)
814+
if (!head) {
815815
if (repo_get_oid(the_repository, "HEAD", &head_oid))
816816
return error(_("bad HEAD - I need a HEAD"));
817+
head = "HEAD";
818+
}
817819

818820
/*
819821
* Check if we are bisecting

0 commit comments

Comments
 (0)