Commit 578aeba97502df26a47255618baa27976bdd0d7f

Edward Thomson 2021-03-20T17:00:33

use git_repository_workdir_path to generate paths Use `git_repository_workdir_path` to generate workdir paths since it will validate the length.

diff --git a/src/blob.c b/src/blob.c
index ef4ad2e..ddc2494 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -198,11 +198,7 @@ int git_blob__create_from_paths(
 	GIT_ASSERT_ARG(hint_path || !try_load_filters);
 
 	if (!content_path) {
-		if (git_repository__ensure_not_bare(repo, "create blob from file") < 0)
-			return GIT_EBAREREPO;
-
-		if (git_buf_joinpath(
-				&path, git_repository_workdir(repo), hint_path) < 0)
+		if (git_repository_workdir_path(&path, repo, hint_path) < 0)
 			return -1;
 
 		content_path = path.ptr;
diff --git a/src/index.c b/src/index.c
index 065cd49..5c33051 100644
--- a/src/index.c
+++ b/src/index.c
@@ -988,7 +988,7 @@ static int index_entry_init(
 	if (git_repository__ensure_not_bare(repo, "create blob from file") < 0)
 		return GIT_EBAREREPO;
 
-	if (git_buf_joinpath(&path, git_repository_workdir(repo), rel_path) < 0)
+	if (git_repository_workdir_path(&path, repo, rel_path) < 0)
 		return -1;
 
 	error = git_path_lstat(path.ptr, &st);
@@ -1532,7 +1532,7 @@ static int add_repo_as_submodule(git_index_entry **out, git_index *index, const 
 	struct stat st;
 	int error;
 
-	if ((error = git_buf_joinpath(&abspath, git_repository_workdir(repo), path)) < 0)
+	if ((error = git_repository_workdir_path(&abspath, repo, path)) < 0)
 		return error;
 
 	if ((error = p_stat(abspath.ptr, &st)) < 0) {
diff --git a/src/mailmap.c b/src/mailmap.c
index 347b433..b69d55e 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -330,6 +330,10 @@ static int mailmap_add_file_ondisk(
 	if (error < 0)
 		goto cleanup;
 
+	error = git_path_validate_workdir_buf(repo, &fullpath);
+	if (error < 0)
+		goto cleanup;
+
 	error = git_futils_readbuffer(&content, fullpath.ptr);
 	if (error < 0)
 		goto cleanup;
diff --git a/src/reader.c b/src/reader.c
index 9672473..4892894 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -98,8 +98,7 @@ static int workdir_reader_read(
 	git_oid id;
 	int error;
 
-	if ((error = git_buf_joinpath(&path,
-		git_repository_workdir(reader->repo), filename)) < 0)
+	if ((error = git_repository_workdir_path(&path, reader->repo, filename)) < 0)
 		goto done;
 
 	if ((error = p_lstat(path.ptr, &st)) < 0) {