Skip to content

Commit 7f53f78

Browse files
peffgitster
authored andcommitted
ll_union_merge(): pass name labels to ll_xdl_merge()
Since cd1d61c (make union merge an xdl merge favor, 2010-03-01), we pass NULL to ll_xdl_merge() for the "name" labels of the ancestor, ours and theirs buffers. We usually use these for annotating conflict markers left in a file. For a union merge, these shouldn't matter; the point of it is that we'd never leave conflict markers in the first place. But there is one code path where we may dereference them: if the file contents appear to be binary, ll_binary_merge() will give up and pass them to warning() to generate a message for the user (that was true even when cd1d61c was written, though the warning was in ll_xdl_merge() back then). That can result in a segfault, though on many systems (including glibc), the printf routines will helpfully just say "(null)" instead. We can extend our binary-union test in t6406 to check stderr, which catches the problem on all systems. This also fixes a warning from "gcc -O3". Unlike lower optimization levels, it inlines enough to see that the NULL can make it to warning() and complains: In function ‘ll_binary_merge’, inlined from ‘ll_xdl_merge’ at ll-merge.c:115:10, inlined from ‘ll_union_merge’ at ll-merge.c:151:9: ll-merge.c:74:4: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 74 | warning("Cannot merge binary files: %s (%s vs. %s)", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 75 | path, name1, name2); | ~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d879ad commit 7f53f78

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

ll-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
151151
o = *opts;
152152
o.variant = XDL_MERGE_FAVOR_UNION;
153153
return ll_xdl_merge(drv_unused, result, path_unused,
154-
orig, NULL, src1, NULL, src2, NULL,
154+
orig, orig_name, src1, name1, src2, name2,
155155
&o, marker_size);
156156
}
157157

t/t6406-merge-attr.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ test_expect_success 'binary files with union attribute' '
221221
printf "two\0" >bin.txt &&
222222
git commit -am two &&
223223
224-
test_must_fail git merge bin-main
224+
test_must_fail git merge bin-main 2>stderr &&
225+
grep -i "warning.*cannot merge.*HEAD vs. bin-main" stderr
225226
'
226227

227228
test_done

0 commit comments

Comments
 (0)