aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/merge-tree.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2024-02-23 08:34:23 +0000
committerJunio C Hamano <gitster@pobox.com>2024-02-23 10:19:40 -0800
commitaa9f618909d30e3f0c7181243e89a81220507e6e (patch)
treeeba8780bfd3266fc0fc9371a0e9024d92d04b036 /builtin/merge-tree.c
parentt4301: verify that merge-tree fails on missing blob objects (diff)
downloadgit-aa9f618909d30e3f0c7181243e89a81220507e6e.tar.gz
git-aa9f618909d30e3f0c7181243e89a81220507e6e.zip
Always check `parse_tree*()`'s return value
Otherwise we may easily run into serious crashes: For example, if we run `init_tree_desc()` directly after a failed `parse_tree()`, we are accessing uninitialized data or trying to dereference `NULL`. Note that the `parse_tree()` function already takes care of showing an error message. The `parse_tree_indirectly()` and `repo_get_commit_tree()` functions do not, therefore those latter call sites need to show a useful error message while the former do not. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge-tree.c')
-rw-r--r--builtin/merge-tree.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 2d4ce5b388..3492a575a6 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -447,12 +447,18 @@ static int real_merge(struct merge_tree_options *o,
if (repo_get_oid_treeish(the_repository, merge_base, &base_oid))
die(_("could not parse as tree '%s'"), merge_base);
base_tree = parse_tree_indirect(&base_oid);
+ if (!base_tree)
+ die(_("unable to read tree (%s)"), oid_to_hex(&base_oid));
if (repo_get_oid_treeish(the_repository, branch1, &head_oid))
die(_("could not parse as tree '%s'"), branch1);
parent1_tree = parse_tree_indirect(&head_oid);
+ if (!parent1_tree)
+ die(_("unable to read tree (%s)"), oid_to_hex(&head_oid));
if (repo_get_oid_treeish(the_repository, branch2, &merge_oid))
die(_("could not parse as tree '%s'"), branch2);
parent2_tree = parse_tree_indirect(&merge_oid);
+ if (!parent2_tree)
+ die(_("unable to read tree (%s)"), oid_to_hex(&merge_oid));
opt.ancestor = merge_base;
merge_incore_nonrecursive(&opt, base_tree, parent1_tree, parent2_tree, &result);