xdl_merge(): fix a segmentation fault when refining conflicts
The function xdl_refine_conflicts() tries to break down huge conflicts by doing a diff on the conflicting regions. However, this does not make sense when one side is empty. Worse, when one side is not only empty, but after EOF, the code accessed unmapped memory. Noticed by Luben Tuikov, Shawn Pearce and Alexandre Julliard, the latter providing a test case. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Dec 28, 2006 at 17:13 UTC
5d6b151fdd0a9e41ba68b444760616da1a008433
2 files changed
+26
t/t6023-merge-file.sh
+22
@@ -112,5 +112,27 @@ EOF
112
test_expect_success "expected conflict markers, with -L" \
113
"diff -u test.txt expect.txt"
114
115
+sed "s/ tu / TU /" < new1.txt > new5.txt
116
+test_expect_failure "conflict in removed tail" \
117
+ "git-merge-file -p orig.txt new1.txt new5.txt > out"
118
+
119
+cat > expect << EOF
120
+Dominus regit me,
121
+et nihil mihi deerit.
122
+In loco pascuae ibi me collocavit,
123
+super aquam refectionis educavit me;
124
+animam meam convertit,
125
+deduxit me super semitas jusitiae,
126
+propter nomen suum.
127
+<<<<<<< orig.txt
128
+=======
129
+Nam et si ambulavero in medio umbrae mortis,
130
+non timebo mala, quoniam TU mecum es:
131
+virga tua et baculus tuus ipsa me consolata sunt.
132
+>>>>>>> new5.txt
133
+EOF
134
+
135
+test_expect_success "expected conflict markers" "diff -u expect out"
136
+
137
test_done
138
xdiff/xmerge.c
+4
@@ -190,6 +190,10 @@ static int xdl_refine_conflicts(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t *m,
190
if (m->mode)
191
continue;
192
193
+ /* no sense refining a conflict when one side is empty */
194
+ if (m->chg1 == 0 || m->chg2 == 0)
195
+ continue;
196
+
197
/*
198
* This probably does not work outside git, since
199
* we have a very simple mmfile structure.