diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-03-13 22:56:17 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-03-13 22:56:17 (GMT) |
commit | bde1e3e80a16a850da95af836ef85c5669c989a2 (patch) | |
tree | a3bfe2636b59654a069631b7da06aa9b5dc24a47 /builtin/checkout.c | |
parent | 8b44e05abf256c5c43116b983719cafca2934952 (diff) | |
parent | 8d2eaf649abd28baa083a723d1e041b26d2be83e (diff) | |
download | git-bde1e3e80a16a850da95af836ef85c5669c989a2.zip git-bde1e3e80a16a850da95af836ef85c5669c989a2.tar.gz git-bde1e3e80a16a850da95af836ef85c5669c989a2.tar.bz2 |
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
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r-- | builtin/checkout.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 9244827..1afc077 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -738,6 +738,7 @@ static int merge_working_tree(const struct checkout_opts *opts, struct tree_desc trees[2]; struct tree *tree; struct unpack_trees_options topts; + const struct object_id *old_commit_oid; memset(&topts, 0, sizeof(topts)); topts.head_idx = -1; @@ -765,9 +766,15 @@ static int merge_working_tree(const struct checkout_opts *opts, &new_branch_info->commit->object.oid : &new_branch_info->oid, NULL); topts.preserve_ignored = !opts->overwrite_ignore; - tree = parse_tree_indirect(old_branch_info->commit ? - &old_branch_info->commit->object.oid : - the_hash_algo->empty_tree); + + old_commit_oid = old_branch_info->commit ? + &old_branch_info->commit->object.oid : + the_hash_algo->empty_tree; + tree = parse_tree_indirect(old_commit_oid); + if (!tree) + die(_("unable to parse commit %s"), + oid_to_hex(old_commit_oid)); + init_tree_desc(&trees[0], tree->buffer, tree->size); parse_tree(new_tree); tree = new_tree; |