Skip to content

Commit f2c1600

Browse files
committed
bisect: handle NULL commit in bisect_successful()
bisect_successful() calls lookup_commit_reference_by_name() to find the first bad commit, then immediately passes the result to repo_format_commit_message() and dereferences commit->object.oid without checking for NULL. lookup_commit_reference_by_name() can return NULL when the ref does not resolve to a valid commit object (e.g., the bisect ref points to a corrupted or missing object). In that case, repo_format_commit_message(NULL, ...) and commit->object.oid are undefined behavior. In practice this is unlikely because bisect_successful() is only called after a successful bisect run has identified the bad commit, but the ref could still become dangling due to a concurrent gc or repository corruption. Add a NULL check and return an error if the commit cannot be looked up. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent c087ba6 commit f2c1600

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

builtin/bisect.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ static int bisect_successful(struct bisect_terms *terms)
660660

661661
refs_read_ref(get_main_ref_store(the_repository), bad_ref, &oid);
662662
commit = lookup_commit_reference_by_name(bad_ref);
663+
if (!commit) {
664+
res = error(_("could not find commit for '%s'"), bad_ref);
665+
free(bad_ref);
666+
return res;
667+
}
663668
repo_format_commit_message(the_repository, commit, "%s", &commit_name,
664669
&pp);
665670

0 commit comments

Comments
 (0)