author | Junio C Hamano <gitster@pobox.com> | |
Tue, 15 Jun 2010 23:02:03 +0000 (01:02 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 16 Jun 2010 19:13:12 +0000 (12:13 -0700) | ||
commit | 42f9852f3c7476b5608ad297443e6d459516f8c0 | |
tree | 9956d2c14b6c2cdddf405156e5ba31a0a51f5a14 | tree | snapshot |
parent | e0a9110176e3b17414b1b38fae8febd0791eaa0c | commit | diff |
common_prefix: simplify and fix scanning for prefixes
common_prefix() scans backwards from the far end of each 'next'
pathspec, starting from 'len', shortening the 'prefix' using 'path' as
a reference.
However, there is a small opportunity for an out-of-bounds access
because len is unconditionally set to prefix-1 after a "direct match"
test failed. This means that if 'next' is shorter than prefix+2, we
read past it.
Instead of a minimal fix, simplify the loop: scan *forward* over the
'next' entry, remembering the last '/' where it matched the prefix
known so far. This is far easier to read and also has the advantage
that we only scan over each entry once.
Acked-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
common_prefix() scans backwards from the far end of each 'next'
pathspec, starting from 'len', shortening the 'prefix' using 'path' as
a reference.
However, there is a small opportunity for an out-of-bounds access
because len is unconditionally set to prefix-1 after a "direct match"
test failed. This means that if 'next' is shorter than prefix+2, we
read past it.
Instead of a minimal fix, simplify the loop: scan *forward* over the
'next' entry, remembering the last '/' where it matched the prefix
known so far. This is far easier to read and also has the advantage
that we only scan over each entry once.
Acked-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c | diff | blob | history |