Skip to content

Commit

Permalink
lstat_cache: guard against full match of length of 'name' parameter
Browse files Browse the repository at this point in the history
longest_path_match() in symlinks.c does exactly what it's name says,
but in some cases that match can be too long, since the
has_*_leading_path() functions assumes that the match will newer be as
long as the name string given to the function.

fix this by adding an extra if test which checks if the match length
is equal to the 'len' parameter.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Kjetil Barvik authored and gitster committed Jul 30, 2009
1 parent 4f6339b commit 7771675
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions symlinks.c
Expand Up @@ -91,6 +91,10 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
longest_path_match(name, len, cache->path, cache->len,
&previous_slash);
match_flags = cache->flags & track_flags & (FL_NOENT|FL_SYMLINK);

if (!(track_flags & FL_FULLPATH) && match_len == len)
match_len = last_slash = previous_slash;

if (match_flags && match_len == cache->len)
return match_flags;
/*
Expand Down
2 changes: 1 addition & 1 deletion t/t6035-merge-dir-to-symlink.sh
Expand Up @@ -26,7 +26,7 @@ test_expect_failure 'keep a/b-2/c/d across checkout' '
test -f a/b-2/c/d
'

test_expect_failure 'checkout should not have deleted a/b-2/c/d' '
test_expect_success 'checkout should not have deleted a/b-2/c/d' '
git checkout HEAD^0 &&
git reset --hard master &&
git checkout start^0 &&
Expand Down

0 comments on commit 7771675

Please sign in to comment.