Skip to content

Commit 91246ee

Browse files
committed
path: use new length validation functions
1 parent 1728e27 commit 91246ee

File tree

10 files changed

+36
-20
lines changed

10 files changed

+36
-20
lines changed

src/attrcache.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "config.h"
1313
#include "sysdir.h"
1414
#include "ignore.h"
15+
#include "path.h"
1516

1617
GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
1718
{
@@ -43,6 +44,7 @@ int git_attr_cache__alloc_file_entry(
4344
const char *path,
4445
git_pool *pool)
4546
{
47+
git_str fullpath_str = GIT_STR_INIT;
4648
size_t baselen = 0, pathlen = strlen(path);
4749
size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1;
4850
git_attr_file_entry *ce;
@@ -66,7 +68,10 @@ int git_attr_cache__alloc_file_entry(
6668
}
6769
memcpy(&ce->fullpath[baselen], path, pathlen);
6870

69-
if (git_fs_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0)
71+
fullpath_str.ptr = ce->fullpath;
72+
fullpath_str.size = pathlen + baselen;
73+
74+
if (git_path_validate_str_length(repo, &fullpath_str) < 0)
7075
return -1;
7176

7277
ce->path = &ce->fullpath[baselen];
@@ -173,7 +178,7 @@ static int attr_cache_lookup(
173178
git_str *p = attr_session ? &attr_session->tmp : &path;
174179

175180
if (git_str_joinpath(p, source->base, source->filename) < 0 ||
176-
git_fs_path_validate_workdir_buf(repo, p) < 0)
181+
git_path_validate_str_length(repo, p) < 0)
177182
return -1;
178183

179184
filename = p->ptr;

src/checkout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static int checkout_target_fullpath(
329329
if (path && git_str_puts(&data->target_path, path) < 0)
330330
return -1;
331331

332-
if (git_fs_path_validate_workdir_buf(data->repo, &data->target_path) < 0)
332+
if (git_path_validate_str_length(data->repo, &data->target_path) < 0)
333333
return -1;
334334

335335
*out = &data->target_path;
@@ -2035,7 +2035,7 @@ static int checkout_merge_path(
20352035
int error = 0;
20362036

20372037
if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
2038-
(error = git_fs_path_validate_workdir_buf(data->repo, out)) < 0)
2038+
(error = git_path_validate_str_length(data->repo, out)) < 0)
20392039
return error;
20402040

20412041
/* Most conflicts simply use the filename in the index */
@@ -2338,7 +2338,7 @@ static int validate_target_directory(checkout_data *data)
23382338
{
23392339
int error;
23402340

2341-
if ((error = git_fs_path_validate_workdir(data->repo, data->opts.target_directory)) < 0)
2341+
if ((error = git_path_validate_length(data->repo, data->opts.target_directory)) < 0)
23422342
return error;
23432343

23442344
if (git_fs_path_isdir(data->opts.target_directory))

src/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "blob.h"
1919
#include "attr_file.h"
2020
#include "array.h"
21+
#include "path.h"
2122

2223
struct git_filter_source {
2324
git_repository *repo;
@@ -1095,7 +1096,7 @@ int git_filter_list_stream_file(
10951096
if ((error = stream_list_init(
10961097
&stream_start, &filter_streams, filters, target)) < 0 ||
10971098
(error = git_fs_path_join_unrooted(&abspath, path, base, NULL)) < 0 ||
1098-
(error = git_fs_path_validate_workdir_buf(repo, &abspath)) < 0)
1099+
(error = git_path_validate_str_length(repo, &abspath)) < 0)
10991100
goto done;
11001101

11011102
initialized = 1;

src/ignore.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "fs_path.h"
1414
#include "config.h"
1515
#include "wildmatch.h"
16+
#include "path.h"
1617

1718
#define GIT_IGNORE_INTERNAL "[internal]exclude"
1819

@@ -320,14 +321,14 @@ int git_ignore__for_path(
320321
(error = git_fs_path_resolve_relative(&local, 0)) < 0 ||
321322
(error = git_fs_path_to_dir(&local)) < 0 ||
322323
(error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
323-
(error = git_fs_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
324+
(error = git_path_validate_str_length(repo, &ignores->dir)) < 0) {
324325
/* Nothing, we just want to stop on the first error */
325326
}
326327

327328
git_str_dispose(&local);
328329
} else {
329330
if (!(error = git_str_joinpath(&ignores->dir, path, "")))
330-
error = git_fs_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size);
331+
error = git_path_validate_str_length(NULL, &ignores->dir);
331332
}
332333

333334
if (error < 0)

src/iterator.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "tree.h"
1111
#include "index.h"
12+
#include "path.h"
1213

1314
#define GIT_ITERATOR_FIRST_ACCESS (1 << 15)
1415
#define GIT_ITERATOR_HONOR_IGNORES (1 << 16)
@@ -1279,7 +1280,7 @@ static int filesystem_iterator_entry_hash(
12791280
iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
12801281

12811282
if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
1282-
!(error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath)))
1283+
!(error = git_path_validate_str_length(iter->base.repo, &fullpath)))
12831284
error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
12841285

12851286
git_str_dispose(&fullpath);
@@ -1361,7 +1362,7 @@ static int filesystem_iterator_frame_push(
13611362
git_str_puts(&root, iter->root);
13621363

13631364
if (git_str_oom(&root) ||
1364-
git_fs_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
1365+
git_path_validate_str_length(iter->base.repo, &root) < 0) {
13651366
error = -1;
13661367
goto done;
13671368
}
@@ -1389,10 +1390,16 @@ static int filesystem_iterator_frame_push(
13891390

13901391
while ((error = git_fs_path_diriter_next(&diriter)) == 0) {
13911392
iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL;
1393+
git_str path_str = GIT_STR_INIT;
13921394
bool dir_expected = false;
13931395

1394-
if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 ||
1395-
(error = git_fs_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0)
1396+
if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
1397+
goto done;
1398+
1399+
path_str.ptr = (char *)path;
1400+
path_str.size = path_len;
1401+
1402+
if ((error = git_path_validate_str_length(iter->base.repo, &path_str)) < 0)
13961403
goto done;
13971404

13981405
GIT_ASSERT(path_len > iter->root_len);
@@ -1565,7 +1572,7 @@ static int filesystem_iterator_is_dir(
15651572
}
15661573

15671574
if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
1568-
(error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
1575+
(error = git_path_validate_str_length(iter->base.repo, &fullpath)) < 0 ||
15691576
(error = p_stat(fullpath.ptr, &st)) < 0)
15701577
goto done;
15711578

src/mailmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "git2/revparse.h"
1717
#include "blob.h"
1818
#include "parse.h"
19+
#include "path.h"
1920

2021
#define MM_FILE ".mailmap"
2122
#define MM_FILE_CONFIG "mailmap.file"
@@ -331,7 +332,7 @@ static int mailmap_add_file_ondisk(
331332
if (error < 0)
332333
goto cleanup;
333334

334-
error = git_fs_path_validate_workdir_buf(repo, &fullpath);
335+
error = git_path_validate_str_length(repo, &fullpath);
335336
if (error < 0)
336337
goto cleanup;
337338

src/refdb_fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ static int refdb_fs_backend__prune_refs(
13621362
git_str_cstr(&relative_path));
13631363

13641364
if (!error)
1365-
error = git_fs_path_validate_filesystem(base_path.ptr, base_path.size);
1365+
error = git_path_validate_str_length(NULL, &base_path);
13661366

13671367
if (error < 0)
13681368
goto cleanup;

src/repository.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "annotated_commit.h"
3333
#include "submodule.h"
3434
#include "worktree.h"
35-
35+
#include "path.h"
3636
#include "strmap.h"
3737

3838
#ifdef GIT_WIN32
@@ -2662,7 +2662,7 @@ int git_repository_workdir_path(
26622662
}
26632663

26642664
if (!(error = git_str_joinpath(out, repo->workdir, path)))
2665-
error = git_fs_path_validate_workdir_buf(repo, out);
2665+
error = git_path_validate_str_length(repo, out);
26662666

26672667
return error;
26682668
}
@@ -2858,7 +2858,7 @@ int git_repository_hashfile(
28582858
GIT_ASSERT_ARG(repo);
28592859

28602860
if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
2861-
(error = git_fs_path_validate_workdir_buf(repo, &full_path)) < 0)
2861+
(error = git_path_validate_str_length(repo, &full_path)) < 0)
28622862
return error;
28632863

28642864
/*

src/submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ int git_submodule__lookup_with_cache(
386386
if (git_str_join3(&path, '/',
387387
git_repository_workdir(repo),
388388
name, DOT_GIT) < 0 ||
389-
git_fs_path_validate_workdir_buf(NULL, &path) < 0)
389+
git_path_validate_str_length(NULL, &path) < 0)
390390
return -1;
391391

392392
if (git_fs_path_exists(path.ptr))

src/worktree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "buf.h"
1111
#include "repository.h"
12+
#include "path.h"
1213

1314
#include "git2/branch.h"
1415
#include "git2/commit.h"
@@ -136,7 +137,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
136137
goto out;
137138
}
138139

139-
if ((error = git_fs_path_validate_workdir(NULL, dir)) < 0)
140+
if ((error = git_path_validate_length(NULL, dir)) < 0)
140141
goto out;
141142

142143
if ((wt = git__calloc(1, sizeof(*wt))) == NULL) {

0 commit comments

Comments
 (0)