Skip to content

Commit 8149e4f

Browse files
committed
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>
1 parent 7b95654 commit 8149e4f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

builtin/stash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,14 +1048,15 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
10481048
struct strbuf diff_output = STRBUF_INIT;
10491049
struct index_state istate = { NULL };
10501050

1051+
init_revisions(&rev, NULL);
1052+
10511053
set_alternate_index_output(stash_index_path.buf);
10521054
if (reset_tree(&info->i_tree, 0, 0)) {
10531055
ret = -1;
10541056
goto done;
10551057
}
10561058
set_alternate_index_output(NULL);
10571059

1058-
init_revisions(&rev, NULL);
10591060
rev.prune_data = ps;
10601061
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
10611062
rev.diffopt.format_callback = add_diff_to_buf;

t/t3903-stash.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ test_expect_success 'stash an added file' '
287287
test new = "$(cat file3)"
288288
'
289289

290+
test_expect_success 'stash --intent-to-add file' '
291+
git reset --hard &&
292+
echo new >file4 &&
293+
git add --intent-to-add file4 &&
294+
test_when_finished "git rm -f file4" &&
295+
test_must_fail git stash
296+
'
297+
290298
test_expect_success 'stash rm then recreate' '
291299
git reset --hard &&
292300
git rm file &&

0 commit comments

Comments
 (0)