Skip to content

Commit 626f9e2

Browse files
committed
index: canonicalize inserted paths safely
When adding to the index, we look to see if a portion of the given path matches a portion of a path in the index. If so, we will use the existing path information. For example, when adding `foo/bar.c`, if there is an index entry to `FOO/other` and the filesystem is case insensitive, then we will put `bar.c` into the existing tree instead of creating a new one with a different case. Use `strncmp` to do that instead of `memcmp`. When we `bsearch` into the index, we locate the position where the new entry would go. The index entry at that position does not necessarily have a relation to the entry we're adding, so we cannot make assumptions and use `memcmp`. Instead, compare them as strings. When canonicalizing paths, we look for the first index entry that matches a given substring.
1 parent 15e6a5a commit 626f9e2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ static int canonicalize_directory_path(
11671167
while ((match = git_vector_get(&index->entries, pos))) {
11681168
if (GIT_IDXENTRY_STAGE(match) != 0) {
11691169
/* conflicts do not contribute to canonical paths */
1170-
} else if (memcmp(search, match->path, search_len) == 0) {
1170+
} else if (strncmp(search, match->path, search_len) == 0) {
11711171
/* prefer an exact match to the input filename */
11721172
best = match;
11731173
best_len = search_len;

0 commit comments

Comments
 (0)