git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 07/12] replay: die when --onto does not peel to a commit

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 10, 2026, 11:39 UTC
Message-ID
<8216769be9eec7489f1039e0211f3e6d3388247b.1783683577.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2174.v2.git.1783683577.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

The `peel_committish()` function calls `repo_peel_to_type()` to convert the given object to a commit, but does not check the return value. When the object exists but cannot be peeled to a commit (e.g., a tree or blob OID is passed as --onto), the return value is NULL. Add an explicit NULL check and die with a descriptive message in that case.

Pointed out by Coverity.
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 replay.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/replay.c b/replay.c
index da531d5bc6..b38cd5efe4 100644
--- a/replay.c
+++ b/replay.c
@@ -36,12 +36,16 @@ static struct commit *peel_committish(struct repository *repo,
 {
 	struct object *obj;
 	struct object_id oid;
+	struct commit *commit;
 
 	if (repo_get_oid(repo, name, &oid))
 		die(_("'%s' is not a valid commit-ish for %s"), name, mode);
 	obj = parse_object_or_die(repo, &oid, name);
-	return (struct commit *)repo_peel_to_type(repo, name, 0, obj,
-						  OBJ_COMMIT);
+	commit = (struct commit *)repo_peel_to_type(repo, name, 0, obj,
+						    OBJ_COMMIT);
+	if (!commit)
+		die(_("'%s' does not point to a commit for %s"), name, mode);
+	return commit;
 }
 
 static char *get_author(const char *message)
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 31 of 36 in “coverity: avoid dereferencing NULL”
  1. 00/11 coverity: avoid dereferencing NULLJohannes Schindelin via GitGitGadget, Jul 9, 2026
  2. 01/11 diffcore-break: guard against NULLed queue entries in merge loopJohannes Schindelin via GitGitGadget, Jul 9, 2026
  3. Junio C HamanoJul 10, 2026
  4. 02/11 diff: handle NULL return from repo_get_commit_tree()Johannes Schindelin via GitGitGadget, Jul 9, 2026
  5. Junio C HamanoJul 10, 2026
  6. 03/11 remote: guard `remote_tracking()` against NULL remoteJohannes Schindelin via GitGitGadget, Jul 9, 2026
  7. Junio C HamanoJul 10, 2026
  8. 04/11 reftable/stack: guard against NULL list_file in stack_destroyJohannes Schindelin via GitGitGadget, Jul 9, 2026
  9. Junio C HamanoJul 10, 2026
  10. 05/11 mailsplit: move NULL check before first use of file handleJohannes Schindelin via GitGitGadget, Jul 9, 2026
  11. Junio C HamanoJul 10, 2026
  12. 06/11 bisect: handle NULL commit in `bisect_successful()`Johannes Schindelin via GitGitGadget, Jul 9, 2026
  13. Junio C HamanoJul 10, 2026
  14. 07/11 replay: die when --onto does not peel to a commitJohannes Schindelin via GitGitGadget, Jul 9, 2026
  15. 08/11 revision: avoid dereferencing NULL in `add_parents_only()`Johannes Schindelin via GitGitGadget, Jul 9, 2026
  16. Junio C HamanoJul 10, 2026
  17. 09/11 pack-bitmap: handle missing bitmap for base MIDXJohannes Schindelin via GitGitGadget, Jul 9, 2026
  18. Junio C HamanoJul 10, 2026
  19. 10/11 bisect: ensure non-NULL `head` before using itJohannes Schindelin via GitGitGadget, Jul 9, 2026
  20. Junio C HamanoJul 10, 2026
  21. 11/11 shallow: fix NULL dereferenceJohannes Schindelin via GitGitGadget, Jul 9, 2026
  22. Junio C HamanoJul 9, 2026
  23. 00/12 coverity: avoid dereferencing NULLJohannes Schindelin via GitGitGadget, Jul 10, 2026
  24. 02/12 diff: handle NULL return from repo_get_commit_tree()Johannes Schindelin via GitGitGadget, Jul 10, 2026
  25. 03/12 remote: guard `remote_tracking()` against NULL remoteJohannes Schindelin via GitGitGadget, Jul 10, 2026
  26. 01/12 diffcore-break: guard against NULLed queue entries in merge loopJohannes Schindelin via GitGitGadget, Jul 10, 2026
  27. 05/12 mailsplit: move NULL check before first use of file handleJohannes Schindelin via GitGitGadget, Jul 10, 2026
  28. 04/12 reftable/stack: guard against NULL list_file in stack_destroyJohannes Schindelin via GitGitGadget, Jul 10, 2026
  29. 06/12 bisect: handle NULL commit in `bisect_successful()`Johannes Schindelin via GitGitGadget, Jul 10, 2026
  30. 08/12 revision: avoid dereferencing NULL in `add_parents_only()`Johannes Schindelin via GitGitGadget, Jul 10, 2026
  31. 07/12 replay: die when --onto does not peel to a commitJohannes Schindelin via GitGitGadget, Jul 10, 2026
  32. 09/12 pack-bitmap: handle missing bitmap for base MIDXJohannes Schindelin via GitGitGadget, Jul 10, 2026
  33. 10/12 bisect: ensure non-NULL `head` before using itJohannes Schindelin via GitGitGadget, Jul 10, 2026
  34. 11/12 shallow: fix NULL dereferenceJohannes Schindelin via GitGitGadget, Jul 10, 2026
  35. 12/12 shallow: give write_one_shallow() its own hex bufferJohannes Schindelin via GitGitGadget, Jul 10, 2026
  36. Junio C HamanoJul 10, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.