git-commit-vandalism/xdiff
Jeff King b777f3fd61 xdiff: clamp function context indices in post-image
After finding a function line for --function-context in the pre-image,
xdl_emit_diff() calculates the equivalent line in the post-image.  It
assumes that the lines between changes are the same on both sides.  If
the option --ignore-blank-lines was also given then this is not
necessarily true.

Clamp the calculation results for start and end of the function context
to prevent out-of-bounds array accesses.

Note that this _just_ fixes the case where our mismatch sends us off the
beginning of the file. There are likely other cases where our assumption
causes us to go to the wrong line within the file. Nobody has developed
a test case yet, and the ultimate fix is likely more complicated than
this patch. But this at least prevents a segfault in the meantime.

Credit for finding the bug goes to "Liu Wei of Tencent Security Xuanwu
Lab".

Reported-by: 刘炜 <lw17qhdz@gmail.com>
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-07-23 14:26:13 -07:00
..
xdiff.h xdiff: provide a separate emit callback for hunks 2018-11-02 20:43:02 +09:00
xdiffi.c Merge branch 'sb/indent-heuristic-optim' 2018-08-17 13:09:57 -07:00
xdiffi.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xemit.c xdiff: clamp function context indices in post-image 2019-07-23 14:26:13 -07:00
xemit.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xhistogram.c xdiff/histogram: remove tail recursion 2018-07-23 10:12:16 -07:00
xinclude.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xmacros.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xmerge.c Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xpatience.c diff: support anchoring line(s) 2017-11-28 10:40:04 +09:00
xprepare.c Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xprepare.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xtypes.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xutils.c xdiff: provide a separate emit callback for hunks 2018-11-02 20:43:02 +09:00
xutils.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00