]> git.ipfire.org Git - thirdparty/git.git/commit - unpack-trees.c
unpack_trees: fix breakage when o->src_index != o->dst_index
authorElijah Newren <newren@gmail.com>
Tue, 24 Apr 2018 06:50:45 +0000 (23:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 May 2018 01:21:28 +0000 (10:21 +0900)
commit7db118303aa04930bea66e855e8659e042f3fa5d
tree3beac161fa1e64c599173194f65c14b88d526164
parent468165c1d8a442994a825f3684528361727cd8c0
unpack_trees: fix breakage when o->src_index != o->dst_index

Currently, all callers of unpack_trees() set o->src_index == o->dst_index.
The code in unpack_trees() does not correctly handle them being different.
There are two separate issues:

First, there is the possibility of memory corruption.  Since
unpack_trees() creates a temporary index in o->result and then discards
o->dst_index and overwrites it with o->result, in the special case that
o->src_index == o->dst_index, it is safe to just reuse o->src_index's
split_index for o->result.  However, when src and dst are different,
reusing o->src_index's split_index for o->result will cause the
split_index to be shared.  If either index then has entries replaced or
removed, it will result in the other index referring to free()'d memory.

Second, we can drop the index extensions.  Previously, we were moving
index extensions from o->dst_index to o->result.  Since o->src_index is
the one that will have the necessary extensions (o->dst_index is likely to
be a new index temporary index created to store the results), we should be
moving the index extensions from there.

Signed-off-by: Elijah Newren <newren@gmail.com>
Acked-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
unpack-trees.c