[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