summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-04-04 22:18:55 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2021-04-28 13:03:34 +0100
commitb457fe27465d92796090c60173fe906fb530155f (patch)
treee6a413475f244cef0f7d79b8529243b75a4a4d3f
parent289aaa414b4d31a0a2412c0395ff7053cef1ccff (diff)
downloadlibgit2-b457fe27465d92796090c60173fe906fb530155f.tar.gz
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.)
-rw-r--r--src/iterator.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/iterator.c b/src/iterator.c
index 073459501..ce9f305ef 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1278,7 +1278,8 @@ static int filesystem_iterator_entry_hash(
return git_repository_hashfile(&entry->id,
iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
- if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)))
+ if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)) &&
+ !(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)))
error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
git_buf_dispose(&fullpath);
@@ -1359,7 +1360,8 @@ static int filesystem_iterator_frame_push(
else
git_buf_puts(&root, iter->root);
- if (git_buf_oom(&root)) {
+ if (git_buf_oom(&root) ||
+ git_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
error = -1;
goto done;
}
@@ -1389,7 +1391,8 @@ static int filesystem_iterator_frame_push(
iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL;
bool dir_expected = false;
- if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
+ if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 ||
+ (error = git_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0)
goto done;
GIT_ASSERT(path_len > iter->root_len);
@@ -1562,7 +1565,8 @@ static int filesystem_iterator_is_dir(
}
if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
- (error = p_stat(fullpath.ptr, &st)) < 0)
+ (error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
+ (error = p_stat(fullpath.ptr, &st)) < 0)
goto done;
*is_dir = S_ISDIR(st.st_mode);