8000 index: correct index has_dir_name check · libgit2/libgit2@eb4c171 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb4c171

Browse files
committed
index: correct index has_dir_name check
`has_dir_name` is used to check for directory/file collisions, and attempts to determine whether the index contains a file with a directory name that is a proper subset of the new index entry that we're trying to add. To determine directory name, the function would walk the path string backwards to identify a `/`, stopping at the end of the string. However, the function assumed that the strings did not start with a `/`. If the paths contain only a single `/` at the beginning of the string, then the function would continue the loop, erroneously, when they should have stopped at the first character. Correct the order of the tests to terminate properly. Credit to Michael Rodler (@f0rki) and Amazon AWS Security.
1 parent 05cf155 commit eb4c171

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/libgit2/index.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,13 @@ static int has_dir_name(git_index *index,
11481148
size_t len, pos;
11491149

11501150
for (;;) {
1151-
if (*--slash == '/')
1152-
break;
1151+
slash--;
1152+
11531153
if (slash <= entry->path)
11541154
return 0;
1155+
1156+
if (*slash == '/')
1157+
break;
11551158
}
11561159
len = slash - name;
11571160

0 commit comments

Comments
 (0)
0