Skip to content

Commit 11a9f4d

Browse files
committed
is_ntfs_dotgit: use a size_t for traversing string
We walk through the "name" string using an int, which can wrap to a negative value and cause us to read random memory before our array (e.g., by creating a tree with a name >2GB, since "int" is still 32 bits even on most 64-bit platforms). Worse, this is easy to trigger during the fsck_tree() check, which is supposed to be protecting us from malicious garbage. Note one bit of trickiness in the existing code: we sometimes assign -1 to "len" at the end of the loop, and then rely on the "len++" in the for-loop's increment to take it back to 0. This is still legal with a size_t, since assigning -1 will turn into SIZE_MAX, which then wraps around to 0 on increment. Signed-off-by: Jeff King <[email protected]>
1 parent 0383bbb commit 11a9f4d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ static int only_spaces_and_periods(const char *path, size_t len, size_t skip)
12241224

12251225
int is_ntfs_dotgit(const char *name)
12261226
{
1227-
int len;
1227+
size_t len;
12281228

12291229
for (len = 0; ; len++)
12301230
if (!name[len] || name[len] == '\\' || is_dir_sep(name[len])) {

0 commit comments

Comments
 (0)