Skip to content

Commit b457fe2

Browse files
committed
iterator: validate workdir paths
Supply the repository for the filesystem and workdir iterators - for workdir iterators, this is non-null and we can lookup the core.longpaths configuration option. (For regular filesystem iterators, this is NULL, so core.longpaths does not apply.)
1 parent 289aaa4 commit b457fe2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/iterator.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,8 @@ static int filesystem_iterator_entry_hash(
12781278
return git_repository_hashfile(&entry->id,
12791279
iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
12801280

1281-
if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)))
1281+
if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)) &&
1282+
!(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)))
12821283
error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
12831284

12841285
git_buf_dispose(&fullpath);
@@ -1359,7 +1360,8 @@ static int filesystem_iterator_frame_push(
13591360
else
13601361
git_buf_puts(&root, iter->root);
13611362

1362-
if (git_buf_oom(&root)) {
1363+
if (git_buf_oom(&root) ||
1364+
git_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
13631365
error = -1;
13641366
goto done;
13651367
}
@@ -1389,7 +1391,8 @@ static int filesystem_iterator_frame_push(
13891391
iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL;
13901392
bool dir_expected = false;
13911393

1392-
if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
1394+
if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 ||
1395+
(error = git_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0)
13931396
goto done;
13941397

13951398
GIT_ASSERT(path_len > iter->root_len);
@@ -1562,7 +1565,8 @@ static int filesystem_iterator_is_dir(
15621565
}
15631566

15641567
if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
1565-
(error = p_stat(fullpath.ptr, &st)) < 0)
1568+
(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
1569+
(error = p_stat(fullpath.ptr, &st)) < 0)
15661570
goto done;
15671571

15681572
*is_dir = S_ISDIR(st.st_mode);

0 commit comments

Comments
 (0)