]> git.ipfire.org Git - thirdparty/git.git/commitdiff
replay: die when --onto does not peel to a commit
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 10 Jul 2026 11:39:31 +0000 (11:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jul 2026 15:13:54 +0000 (08:13 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
replay.c

index da531d5bc68add946f7045f1169ebdcf0eb02631..b38cd5efe49c50881878e118e685994d6f815988 100644 (file)
--- 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)