summaryrefslogtreecommitdiff
path: root/ll-merge.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-15 20:12:58 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-16 13:21:57 -0800
commit2b6a95e6250ff2abd8158e53b2a4e5e4996a8767 (patch)
tree5ece2dd5cb50c2162eb9471a4dd8d3631b37d226 /ll-merge.c
parenta2558fb8e1e387b630312311e1d22c95663da5d0 (diff)
downloadgit-jk/merge-tree-merge-blobs.tar.gz
merge_blobs: use strbuf instead of manually-sized mmfile_tjk/merge-tree-merge-blobs
The ancient merge_blobs function (which is used nowhere except in the equally ancient git-merge-tree, which does not itself seem to be called by any modern git code), tries to create a plausible base object for an add/add conflict by finding the common parts of the "ours" and "theirs" blobs. It does so by calling xdiff with XDIFF_EMIT_COMMON, and stores the result in a buffer that is as big as the smaller of "ours" and "theirs". In theory, this is right; we cannot have more common content than is in the smaller of the two blobs. But in practice, xdiff may give us more: if neither file ends in a newline, we get the "\nNo newline at end of file" marker. This is somewhat of a bug in itself (the "no newline" string becomes part of the blob output!), but much worse is that we may overflow our output buffer with this string (if the common content was otherwise close to the size of the smaller blob). The minimal fix for the memory corruption is to size the buffer appropriately. We could do so by manually adding in an extra 29 bytes for the "no newline" string to our buffer size. But that's somewhat fragile. Instead, let's replace the fixed-size output buffer with a strbuf which can grow as necessary. Reported-by: Stefan Frühwirth <stefan.fruehwirth@uni-graz.at> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'll-merge.c')
0 files changed, 0 insertions, 0 deletions