]> git.ipfire.org Git - thirdparty/git.git/commit - apply.c
apply: avoid out-of-bounds access in fuzzy_matchlines()
authorRené Scharfe <l.s.r@web.de>
Sat, 11 Nov 2017 14:10:19 +0000 (15:10 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 12 Nov 2017 05:41:40 +0000 (14:41 +0900)
commit6ce15ce576afb0510e9d6189ff3780369fdc5b2b
tree6f3b03ea6f514b7fc2130e0860d1880cd30c763d
parent39aaab109972d6bbc1d0ffe5d4de47bbd4b8bb07
apply: avoid out-of-bounds access in fuzzy_matchlines()

fuzzy_matchlines() uses a pointers to the first and last characters of
two lines to keep track while matching them.  This makes it impossible
to deal with empty strings.  It accesses characters before the start of
empty lines.  It can also access characters after the end when checking
for trailing whitespace in the main loop.

Avoid that by using pointers to the first character and the one *after*
the last one.  This is well-defined as long as the latter is not
dereferenced.  Basically rewrite the function based on that premise; it
becomes much simpler as a result.  There is no need to check for
leading whitespace outside of the main loop anymore.

Reported-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
apply.c