Skip to content

Commit bde1e3e

Browse files
committed
Merge branch 'gc/parse-tree-indirect-errors'
Check the return value from parse_tree_indirect() to turn segfaults into calls to die(). * gc/parse-tree-indirect-errors: checkout, clone: die if tree cannot be parsed
2 parents 8b44e05 + 8d2eaf6 commit bde1e3e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

builtin/checkout.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
738738
struct tree_desc trees[2];
739739
struct tree *tree;
740740
struct unpack_trees_options topts;
741+
const struct object_id *old_commit_oid;
741742

742743
memset(&topts, 0, sizeof(topts));
743744
topts.head_idx = -1;
@@ -765,9 +766,15 @@ static int merge_working_tree(const struct checkout_opts *opts,
765766
&new_branch_info->commit->object.oid :
766767
&new_branch_info->oid, NULL);
767768
topts.preserve_ignored = !opts->overwrite_ignore;
768-
tree = parse_tree_indirect(old_branch_info->commit ?
769-
&old_branch_info->commit->object.oid :
770-
the_hash_algo->empty_tree);
769+
770+
old_commit_oid = old_branch_info->commit ?
771+
&old_branch_info->commit->object.oid :
772+
the_hash_algo->empty_tree;
773+
tree = parse_tree_indirect(old_commit_oid);
774+
if (!tree)
775+
die(_("unable to parse commit %s"),
776+
oid_to_hex(old_commit_oid));
777+
771778
init_tree_desc(&trees[0], tree->buffer, tree->size);
772779
parse_tree(new_tree);
773780
tree = new_tree;

builtin/clone.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ static int checkout(int submodule_progress, int filter_submodules)
700700
init_checkout_metadata(&opts.meta, head, &oid, NULL);
701701

702702
tree = parse_tree_indirect(&oid);
703+
if (!tree)
704+
die(_("unable to parse commit %s"), oid_to_hex(&oid));
703705
parse_tree(tree);
704706
init_tree_desc(&t, tree->buffer, tree->size);
705707
if (unpack_trees(1, &t, &opts) < 0)

0 commit comments

Comments
 (0)