Skip to content

Commit 578aeba

Browse files
committed
use git_repository_workdir_path to generate paths
Use `git_repository_workdir_path` to generate workdir paths since it will validate the length.
1 parent 99ddfd5 commit 578aeba

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

src/blob.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,7 @@ int git_blob__create_from_paths(
198198
GIT_ASSERT_ARG(hint_path || !try_load_filters);
199199

200200
if (!content_path) {
201-
if (git_repository__ensure_not_bare(repo, "create blob from file") < 0)
202-
return GIT_EBAREREPO;
203-
204-
if (git_buf_joinpath(
205-
&path, git_repository_workdir(repo), hint_path) < 0)
201+
if (git_repository_workdir_path(&path, repo, hint_path) < 0)
206202
return -1;
207203

208204
content_path = path.ptr;

src/index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ static int index_entry_init(
988988
if (git_repository__ensure_not_bare(repo, "create blob from file") < 0)
989989
return GIT_EBAREREPO;
990990

991-
if (git_buf_joinpath(&path, git_repository_workdir(repo), rel_path) < 0)
991+
if (git_repository_workdir_path(&path, repo, rel_path) < 0)
992992
return -1;
993993

994994
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
15321532
struct stat st;
15331533
int error;
15341534

1535-
if ((error = git_buf_joinpath(&abspath, git_repository_workdir(repo), path)) < 0)
1535+
if ((error = git_repository_workdir_path(&abspath, repo, path)) < 0)
15361536
return error;
15371537

15381538
if ((error = p_stat(abspath.ptr, &st)) < 0) {

src/mailmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ static int mailmap_add_file_ondisk(
330330
if (error < 0)
331331
goto cleanup;
332332

333+
error = git_path_validate_workdir_buf(repo, &fullpath);
334+
if (error < 0)
335+
goto cleanup;
336+
333337
error = git_futils_readbuffer(&content, fullpath.ptr);
334338
if (error < 0)
335339
goto cleanup;

src/reader.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ static int workdir_reader_read(
9898
git_oid id;
9999
int error;
100100

101-
if ((error = git_buf_joinpath(&path,
102-
git_repository_workdir(reader->repo), filename)) < 0)
101+
if ((error = git_repository_workdir_path(&path, reader->repo, filename)) < 0)
103102
goto done;
104103

105104
if ((error = p_lstat(path.ptr, &st)) < 0) {

0 commit comments

Comments
 (0)