Initialize rev before using &rev.pending

If reset_tree returns a non-zero value, stash_working_tree calls
object_array_clear with &rev.pending before rev is initialized.  This
causes a segmentation fault.  Prevent this by initializing rev before
calling reset_tree.

This fixes #2006.

Signed-off-by: Matthew Kraai <mkraai@its.jnj.com>
This commit is contained in:
Matthew Kraai
2019-01-04 09:34:33 -08:00
parent 7b95654d1c
commit 8149e4f8d5
2 changed files with 10 additions and 1 deletions

View File

@@ -1048,6 +1048,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
struct strbuf diff_output = STRBUF_INIT;
struct index_state istate = { NULL };
init_revisions(&rev, NULL);
set_alternate_index_output(stash_index_path.buf);
if (reset_tree(&info->i_tree, 0, 0)) {
ret = -1;
@@ -1055,7 +1057,6 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
}
set_alternate_index_output(NULL);
init_revisions(&rev, NULL);
rev.prune_data = ps;
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = add_diff_to_buf;

View File

@@ -287,6 +287,14 @@ test_expect_success 'stash an added file' '
test new = "$(cat file3)"
'
test_expect_success 'stash --intent-to-add file' '
git reset --hard &&
echo new >file4 &&
git add --intent-to-add file4 &&
test_when_finished "git rm -f file4" &&
test_must_fail git stash
'
test_expect_success 'stash rm then recreate' '
git reset --hard &&
git rm file &&