summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-04-04 20:46:40 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2021-04-28 13:03:34 +0100
commit289aaa414b4d31a0a2412c0395ff7053cef1ccff (patch)
treedf1e3fb7132f98287a3808f2db564ca15cae6f8e
parent9fb755d561e149b81950c7cc7d8cb5131b24079b (diff)
downloadlibgit2-289aaa414b4d31a0a2412c0395ff7053cef1ccff.tar.gz
ignore: validate workdir paths for ignore files
-rw-r--r--src/ignore.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/ignore.c b/src/ignore.c
index 085b0e981..700a6729c 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -309,12 +309,17 @@ int git_ignore__for_path(
if ((error = git_path_dirname_r(&local, path)) < 0 ||
(error = git_path_resolve_relative(&local, 0)) < 0 ||
(error = git_path_to_dir(&local)) < 0 ||
- (error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0)
- {;} /* Nothing, we just want to stop on the first error */
+ (error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
+ (error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
+ /* Nothing, we just want to stop on the first error */
+ }
+
git_buf_dispose(&local);
} else {
- error = git_buf_joinpath(&ignores->dir, path, "");
+ if (!(error = git_buf_joinpath(&ignores->dir, path, "")))
+ error = git_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size);
}
+
if (error < 0)
goto cleanup;
@@ -590,7 +595,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
git_attr_fnmatch *match;
int ignored;
git_buf path = GIT_BUF_INIT;
- const char *wd, *filename;
+ const char *filename;
git_index *idx;
if ((error = git_repository__ensure_not_bare(
@@ -598,8 +603,6 @@ int git_ignore__check_pathspec_for_exact_ignores(
(error = git_repository_index(&idx, repo)) < 0)
return error;
- wd = git_repository_workdir(repo);
-
git_vector_foreach(vspec, i, match) {
/* skip wildcard matches (if they are being used) */
if ((match->flags & GIT_ATTR_FNMATCH_HASWILD) != 0 &&
@@ -612,7 +615,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
if (git_index_get_bypath(idx, filename, 0) != NULL)
continue;
- if ((error = git_buf_joinpath(&path, wd, filename)) < 0)
+ if ((error = git_repository_workdir_path(&path, repo, filename)) < 0)
break;
/* is there a file on disk that matches this exactly? */