summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-03-20 09:52:17 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2021-04-14 23:02:51 +0100
commit88323cd0723cf2f6cb6daa1d2fc275a3fdde5efc (patch)
tree1d2d7bd8e7b8096ab0dc0d45b8b4393c133044f9 /src
parent78abfb172b170aca95527c32d8cea17994106c3e (diff)
downloadlibgit2-88323cd0723cf2f6cb6daa1d2fc275a3fdde5efc.tar.gz
path: git_path_isvalid -> git_path_validate
If we want to validate more and different types of paths, the name `git_path_validate` makes that easier and more expressive. We can add, for example, `git_path_validate_foo` while the current name makes that less ergonomic.
Diffstat (limited to 'src')
-rw-r--r--src/checkout.c4
-rw-r--r--src/index.c2
-rw-r--r--src/path.c2
-rw-r--r--src/path.h11
-rw-r--r--src/refdb_fs.c4
-rw-r--r--src/submodule.c2
-rw-r--r--src/tree.c2
7 files changed, 16 insertions, 11 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 65487993b..ba75839f7 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1278,14 +1278,14 @@ static int checkout_verify_paths(
unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS;
if (action & CHECKOUT_ACTION__REMOVE) {
- if (!git_path_isvalid(repo, delta->old_file.path, delta->old_file.mode, flags)) {
+ if (!git_path_validate(repo, delta->old_file.path, delta->old_file.mode, flags)) {
git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path);
return -1;
}
}
if (action & ~CHECKOUT_ACTION__REMOVE) {
- if (!git_path_isvalid(repo, delta->new_file.path, delta->new_file.mode, flags)) {
+ if (!git_path_validate(repo, delta->new_file.path, delta->new_file.mode, flags)) {
git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path);
return -1;
}
diff --git a/src/index.c b/src/index.c
index 3d46030f7..065cd490b 100644
--- a/src/index.c
+++ b/src/index.c
@@ -944,7 +944,7 @@ static int index_entry_create(
if (st)
mode = st->st_mode;
- if (!git_path_isvalid(repo, path, mode, path_valid_flags)) {
+ if (!git_path_validate(repo, path, mode, path_valid_flags)) {
git_error_set(GIT_ERROR_INDEX, "invalid path: '%s'", path);
return -1;
}
diff --git a/src/path.c b/src/path.c
index 8ebb58158..b4b15660b 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1877,7 +1877,7 @@ GIT_INLINE(unsigned int) dotgit_flags(
return flags;
}
-bool git_path_isvalid(
+bool git_path_validate(
git_repository *repo,
const char *path,
uint16_t mode,
diff --git a/src/path.h b/src/path.h
index bfef1b8a8..1ff15dff1 100644
--- a/src/path.h
+++ b/src/path.h
@@ -626,15 +626,20 @@ extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or
#define GIT_PATH_REJECT_INDEX_DEFAULTS \
GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
-/*
- * Determine whether a path is a valid git path or not - this must not contain
+/**
+ * Validate a "bare" git path. This ensures that the given path is legal
+ * to place in the index or a tree. This should be checked by mechanisms
+ * like `git_index_add` and `git_treebuilder_insert` when taking user
+ * data, and by `git_checkout` before constructing on-disk paths.
+ *
+ * This will ensure that a git path does not contain any "unsafe" components,
* a '.' or '..' component, or a component that is ".git" (in any case).
*
* `repo` is optional. If specified, it will be used to determine the short
* path name to reject (if `GIT_PATH_REJECT_DOS_SHORTNAME` is specified),
* in addition to the default of "git~1".
*/
-extern bool git_path_isvalid(
+extern bool git_path_validate(
git_repository *repo,
const char *path,
uint16_t mode,
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index a5a6b3c0e..551732f6e 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -789,7 +789,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
GIT_ASSERT_ARG(backend);
GIT_ASSERT_ARG(name);
- if (!git_path_isvalid(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
+ if (!git_path_validate(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name);
return GIT_EINVALIDSPEC;
}
@@ -1828,7 +1828,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
repo = backend->repo;
- if (!git_path_isvalid(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
+ if (!git_path_validate(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname);
return GIT_EINVALIDSPEC;
}
diff --git a/src/submodule.c b/src/submodule.c
index 50bde2c63..e54cd6a29 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -418,7 +418,7 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag
git_buf_attach_notowned(&buf, name, strlen(name));
}
- isvalid = git_path_isvalid(repo, buf.ptr, 0, flags);
+ isvalid = git_path_validate(repo, buf.ptr, 0, flags);
git_buf_dispose(&buf);
return isvalid;
diff --git a/src/tree.c b/src/tree.c
index 5abcc9d3b..76821e3a0 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -54,7 +54,7 @@ GIT_INLINE(git_filemode_t) normalize_filemode(git_filemode_t filemode)
static int valid_entry_name(git_repository *repo, const char *filename)
{
return *filename != '\0' &&
- git_path_isvalid(repo, filename, 0,
+ git_path_validate(repo, filename, 0,
GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT | GIT_PATH_REJECT_SLASH);
}