Skip to content

Commit 289aaa4

Browse files
committed
ignore: validate workdir paths for ignore files
1 parent 9fb755d commit 289aaa4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/ignore.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,17 @@ int git_ignore__for_path(
309309
if ((error = git_path_dirname_r(&local, path)) < 0 ||
310310
(error = git_path_resolve_relative(&local, 0)) < 0 ||
311311
(error = git_path_to_dir(&local)) < 0 ||
312-
(error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0)
313-
{;} /* Nothing, we just want to stop on the first error */
312+
(error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
313+
(error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
314+
/* Nothing, we just want to stop on the first error */
315+
}
316+
314317
git_buf_dispose(&local);
315318
} else {
316-
error = git_buf_joinpath(&ignores->dir, path, "");
319+
if (!(error = git_buf_joinpath(&ignores->dir, path, "")))
320+
error = git_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size);
317321
}
322+
318323
if (error < 0)
319324
goto cleanup;
320325

@@ -590,16 +595,14 @@ int git_ignore__check_pathspec_for_exact_ignores(
590595
git_attr_fnmatch *match;
591596
int ignored;
592597
git_buf path = GIT_BUF_INIT;
593-
const char *wd, *filename;
598+
const char *filename;
594599
git_index *idx;
595600

596601
if ((error = git_repository__ensure_not_bare(
597602
repo, "validate pathspec")) < 0 ||
598603
(error = git_repository_index(&idx, repo)) < 0)
599604
return error;
600605

601-
wd = git_repository_workdir(repo);
602-
603606
git_vector_foreach(vspec, i, match) {
604607
/* skip wildcard matches (if they are being used) */
605608
if ((match->flags & GIT_ATTR_FNMATCH_HASWILD) != 0 &&
@@ -612,7 +615,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
612615
if (git_index_get_bypath(idx, filename, 0) != NULL)
613616
continue;
614617

615-
if ((error = git_buf_joinpath(&path, wd, filename)) < 0)
618+
if ((error = git_repository_workdir_path(&path, repo, filename)) < 0)
616619
break;
617620

618621
/* is there a file on disk that matches this exactly? */

0 commit comments

Comments
 (0)