summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-03-20 17:00:33 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2021-04-28 13:03:34 +0100
commit578aeba97502df26a47255618baa27976bdd0d7f (patch)
tree2eb3a14a18afcff0f104b52cc8f693714a1cc870
parent99ddfd5c251fb814b33d38e07529114f323527f6 (diff)
downloadlibgit2-578aeba97502df26a47255618baa27976bdd0d7f.tar.gz
use git_repository_workdir_path to generate paths
Use `git_repository_workdir_path` to generate workdir paths since it will validate the length.
-rw-r--r--src/blob.c6
-rw-r--r--src/index.c4
-rw-r--r--src/mailmap.c4
-rw-r--r--src/reader.c3
4 files changed, 8 insertions, 9 deletions
diff --git a/src/blob.c b/src/blob.c
index ef4ad2e7e..ddc2494c8 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 065cd490b..5c3305170 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 347b43391..b69d55e2e 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 9672473e8..48928940d 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) {