From: Johannes Schindelin via GitGitGadget Date: Thu, 09 Jul 2026 09:42:33 GMT Subject: [PATCH 06/11] bisect: handle NULL commit in `bisect_successful()` Message-ID: <704137510808ade246c6f1463e88a8e3041e0f7d.1783590159.git.gitgitgadget@gmail.com> In-Reply-To: From: Johannes Schindelin When `lookup_commit_reference_by_name()` is called to find the first bad commit, the result is passed to `repo_format_commit_message()` immediately, which dereferences commit without checking for NULL. However, the commit could be NULL, even though 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. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- builtin/bisect.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/bisect.c b/builtin/bisect.c index e7c2d2f3bb..6ff600c856 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -663,6 +663,11 @@ static int bisect_successful(struct bisect_terms *terms) refs_read_ref(get_main_ref_store(the_repository), bad_ref, &oid); commit = lookup_commit_reference_by_name(bad_ref); + if (!commit) { + res = error(_("could not find commit for '%s'"), bad_ref); + free(bad_ref); + return res; + } repo_format_commit_message(the_repository, commit, "%s", &commit_name, &pp); -- gitgitgadget