Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit d49a708

Browse files
kbleesdscho
authored andcommitted
Win32: fix checkout problem with directories exceeding MAX_PATH
The lstat_cache in symlinks.c checks if the leading directory exists using PATH_MAX-bounded string operations, which fails if a directory is longer than 259 characters. Signed-off-by: Karsten Blees <[email protected]>
1 parent 840d1f9 commit d49a708

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

compat/mingw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf)
889889
static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
890890
{
891891
int namelen;
892-
char alt_name[PATH_MAX];
892+
char alt_name[MAX_LONG_PATH];
893893

894894
if (!do_lstat(follow, file_name, buf))
895895
return 0;
@@ -905,7 +905,7 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
905905
return -1;
906906
while (namelen && file_name[namelen-1] == '/')
907907
--namelen;
908-
if (!namelen || namelen >= PATH_MAX)
908+
if (!namelen || namelen >= MAX_LONG_PATH)
909909
return -1;
910910

911911
memcpy(alt_name, file_name, namelen);

symlinks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int lstat_cache_matchlen(struct cache_def *cache,
121121
*/
122122
*ret_flags = FL_DIR;
123123
last_slash_dir = last_slash;
124-
max_len = len < PATH_MAX ? len : PATH_MAX;
124+
max_len = len < MAX_LONG_PATH ? len : MAX_LONG_PATH;
125125
while (match_len < max_len) {
126126
do {
127127
cache->path[match_len] = name[match_len];
@@ -158,12 +158,12 @@ static int lstat_cache_matchlen(struct cache_def *cache,
158158
* for the moment!
159159
*/
160160
save_flags = *ret_flags & track_flags & (FL_NOENT|FL_SYMLINK);
161-
if (save_flags && last_slash > 0 && last_slash <= PATH_MAX) {
161+
if (save_flags && last_slash > 0 && last_slash <= MAX_LONG_PATH) {
162162
cache->path[last_slash] = '\0';
163163
cache->len = last_slash;
164164
cache->flags = save_flags;
165165
} else if ((track_flags & FL_DIR) &&
166-
last_slash_dir > 0 && last_slash_dir <= PATH_MAX) {
166+
last_slash_dir > 0 && last_slash_dir <= MAX_LONG_PATH) {
167167
/*
168168
* We have a separate test for the directory case,
169169
* since it could be that we have found a symlink or a
@@ -274,7 +274,7 @@ static int threaded_has_dirs_only_path(struct cache_def *cache, const char *name
274274
}
275275

276276
static struct removal_def {
277-
char path[PATH_MAX];
277+
char path[MAX_LONG_PATH];
278278
int len;
279279
} removal;
280280

0 commit comments

Comments
 (0)