path: use new length validation functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
diff --git a/src/attrcache.c b/src/attrcache.c
index 15c7fab..b16d95c 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -12,6 +12,7 @@
#include "config.h"
#include "sysdir.h"
#include "ignore.h"
+#include "path.h"
GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
{
@@ -43,6 +44,7 @@ int git_attr_cache__alloc_file_entry(
const char *path,
git_pool *pool)
{
+ git_str fullpath_str = GIT_STR_INIT;
size_t baselen = 0, pathlen = strlen(path);
size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1;
git_attr_file_entry *ce;
@@ -66,7 +68,10 @@ int git_attr_cache__alloc_file_entry(
}
memcpy(&ce->fullpath[baselen], path, pathlen);
- if (git_fs_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0)
+ fullpath_str.ptr = ce->fullpath;
+ fullpath_str.size = pathlen + baselen;
+
+ if (git_path_validate_str_length(repo, &fullpath_str) < 0)
return -1;
ce->path = &ce->fullpath[baselen];
@@ -173,7 +178,7 @@ static int attr_cache_lookup(
git_str *p = attr_session ? &attr_session->tmp : &path;
if (git_str_joinpath(p, source->base, source->filename) < 0 ||
- git_fs_path_validate_workdir_buf(repo, p) < 0)
+ git_path_validate_str_length(repo, p) < 0)
return -1;
filename = p->ptr;
diff --git a/src/checkout.c b/src/checkout.c
index ad4eddd..5733f4a 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -329,7 +329,7 @@ static int checkout_target_fullpath(
if (path && git_str_puts(&data->target_path, path) < 0)
return -1;
- if (git_fs_path_validate_workdir_buf(data->repo, &data->target_path) < 0)
+ if (git_path_validate_str_length(data->repo, &data->target_path) < 0)
return -1;
*out = &data->target_path;
@@ -2035,7 +2035,7 @@ static int checkout_merge_path(
int error = 0;
if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
- (error = git_fs_path_validate_workdir_buf(data->repo, out)) < 0)
+ (error = git_path_validate_str_length(data->repo, out)) < 0)
return error;
/* Most conflicts simply use the filename in the index */
@@ -2338,7 +2338,7 @@ static int validate_target_directory(checkout_data *data)
{
int error;
- if ((error = git_fs_path_validate_workdir(data->repo, data->opts.target_directory)) < 0)
+ if ((error = git_path_validate_length(data->repo, data->opts.target_directory)) < 0)
return error;
if (git_fs_path_isdir(data->opts.target_directory))
diff --git a/src/filter.c b/src/filter.c
index 9502960..2712e8c 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -18,6 +18,7 @@
#include "blob.h"
#include "attr_file.h"
#include "array.h"
+#include "path.h"
struct git_filter_source {
git_repository *repo;
@@ -1095,7 +1096,7 @@ int git_filter_list_stream_file(
if ((error = stream_list_init(
&stream_start, &filter_streams, filters, target)) < 0 ||
(error = git_fs_path_join_unrooted(&abspath, path, base, NULL)) < 0 ||
- (error = git_fs_path_validate_workdir_buf(repo, &abspath)) < 0)
+ (error = git_path_validate_str_length(repo, &abspath)) < 0)
goto done;
initialized = 1;
diff --git a/src/ignore.c b/src/ignore.c
index e7d8b79..cee58d7 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -13,6 +13,7 @@
#include "fs_path.h"
#include "config.h"
#include "wildmatch.h"
+#include "path.h"
#define GIT_IGNORE_INTERNAL "[internal]exclude"
@@ -320,14 +321,14 @@ int git_ignore__for_path(
(error = git_fs_path_resolve_relative(&local, 0)) < 0 ||
(error = git_fs_path_to_dir(&local)) < 0 ||
(error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
- (error = git_fs_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
+ (error = git_path_validate_str_length(repo, &ignores->dir)) < 0) {
/* Nothing, we just want to stop on the first error */
}
git_str_dispose(&local);
} else {
if (!(error = git_str_joinpath(&ignores->dir, path, "")))
- error = git_fs_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size);
+ error = git_path_validate_str_length(NULL, &ignores->dir);
}
if (error < 0)
diff --git a/src/iterator.c b/src/iterator.c
index a627e0f..a4337bb 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -9,6 +9,7 @@
#include "tree.h"
#include "index.h"
+#include "path.h"
#define GIT_ITERATOR_FIRST_ACCESS (1 << 15)
#define GIT_ITERATOR_HONOR_IGNORES (1 << 16)
@@ -1279,7 +1280,7 @@ static int filesystem_iterator_entry_hash(
iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
- !(error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath)))
+ !(error = git_path_validate_str_length(iter->base.repo, &fullpath)))
error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
git_str_dispose(&fullpath);
@@ -1361,7 +1362,7 @@ static int filesystem_iterator_frame_push(
git_str_puts(&root, iter->root);
if (git_str_oom(&root) ||
- git_fs_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
+ git_path_validate_str_length(iter->base.repo, &root) < 0) {
error = -1;
goto done;
}
@@ -1389,10 +1390,16 @@ static int filesystem_iterator_frame_push(
while ((error = git_fs_path_diriter_next(&diriter)) == 0) {
iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL;
+ git_str path_str = GIT_STR_INIT;
bool dir_expected = false;
- if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 ||
- (error = git_fs_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0)
+ if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
+ goto done;
+
+ path_str.ptr = (char *)path;
+ path_str.size = path_len;
+
+ if ((error = git_path_validate_str_length(iter->base.repo, &path_str)) < 0)
goto done;
GIT_ASSERT(path_len > iter->root_len);
@@ -1565,7 +1572,7 @@ static int filesystem_iterator_is_dir(
}
if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
- (error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
+ (error = git_path_validate_str_length(iter->base.repo, &fullpath)) < 0 ||
(error = p_stat(fullpath.ptr, &st)) < 0)
goto done;
diff --git a/src/mailmap.c b/src/mailmap.c
index 4fbb1ae..4336fe3 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -16,6 +16,7 @@
#include "git2/revparse.h"
#include "blob.h"
#include "parse.h"
+#include "path.h"
#define MM_FILE ".mailmap"
#define MM_FILE_CONFIG "mailmap.file"
@@ -331,7 +332,7 @@ static int mailmap_add_file_ondisk(
if (error < 0)
goto cleanup;
- error = git_fs_path_validate_workdir_buf(repo, &fullpath);
+ error = git_path_validate_str_length(repo, &fullpath);
if (error < 0)
goto cleanup;
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index acd6270..dc291d0 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1362,7 +1362,7 @@ static int refdb_fs_backend__prune_refs(
git_str_cstr(&relative_path));
if (!error)
- error = git_fs_path_validate_filesystem(base_path.ptr, base_path.size);
+ error = git_path_validate_str_length(NULL, &base_path);
if (error < 0)
goto cleanup;
diff --git a/src/repository.c b/src/repository.c
index 2f7ae9b..f564453 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -32,7 +32,7 @@
#include "annotated_commit.h"
#include "submodule.h"
#include "worktree.h"
-
+#include "path.h"
#include "strmap.h"
#ifdef GIT_WIN32
@@ -2662,7 +2662,7 @@ int git_repository_workdir_path(
}
if (!(error = git_str_joinpath(out, repo->workdir, path)))
- error = git_fs_path_validate_workdir_buf(repo, out);
+ error = git_path_validate_str_length(repo, out);
return error;
}
@@ -2858,7 +2858,7 @@ int git_repository_hashfile(
GIT_ASSERT_ARG(repo);
if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
- (error = git_fs_path_validate_workdir_buf(repo, &full_path)) < 0)
+ (error = git_path_validate_str_length(repo, &full_path)) < 0)
return error;
/*
diff --git a/src/submodule.c b/src/submodule.c
index ffe29cc..0370ac8 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -386,7 +386,7 @@ int git_submodule__lookup_with_cache(
if (git_str_join3(&path, '/',
git_repository_workdir(repo),
name, DOT_GIT) < 0 ||
- git_fs_path_validate_workdir_buf(NULL, &path) < 0)
+ git_path_validate_str_length(NULL, &path) < 0)
return -1;
if (git_fs_path_exists(path.ptr))
diff --git a/src/worktree.c b/src/worktree.c
index f0fc6d7..e08d6d4 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -9,6 +9,7 @@
#include "buf.h"
#include "repository.h"
+#include "path.h"
#include "git2/branch.h"
#include "git2/commit.h"
@@ -136,7 +137,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
goto out;
}
- if ((error = git_fs_path_validate_workdir(NULL, dir)) < 0)
+ if ((error = git_path_validate_length(NULL, dir)) < 0)
goto out;
if ((wt = git__calloc(1, sizeof(*wt))) == NULL) {