summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorLibravatar Jiang Xin <worldhello.net@gmail.com>2022-04-13 14:51:53 +0800
committerLibravatar Jiang Xin <worldhello.net@gmail.com>2022-04-13 14:51:53 +0800
commit61de00a32115b6090891f20797fdfd1501709ab9 (patch)
treee6a0290cef9e52589a8b78e55dbae3daf559e202 /setup.c
parentMerge branch 'fr_2.36_rnd1' of github.com:jnavila/git (diff)
parentGit 2.36-rc2 (diff)
downloadtgif-61de00a32115b6090891f20797fdfd1501709ab9.tar.xz
Merge branch 'master' of github.com:git/git
* 'master' of github.com:git/git: (25 commits) Git 2.36-rc2 i18n: fix some badly formatted i18n strings Git 2.36-rc1 t9902: split test to run on appropriate systems ls-tree doc: document interaction with submodules Documentation: add --batch-command to cat-file synopsis git-ls-tree.txt: fix the name of "%(objectsize:padded)" submodule-helper: fix usage string doc: replace "--" with {litdd} in credential-cache/fsmonitor contrib/scalar: fix 'all' target in Makefile Documentation/Makefile: fix "make info" regression in dad9cd7d518 configure.ac: fix HAVE_SYNC_FILE_RANGE definition git-compat-util: really support openssl as a source of entropy ls-tree: `-l` should not imply recursive listing Git 2.35.2 Git 2.34.2 Git 2.33.2 Git 2.32.1 Git 2.31.2 Git 2.30.3 ...
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/setup.c b/setup.c
index 04ce33cdcd..c8f67bfed5 100644
--- a/setup.c
+++ b/setup.c
@@ -5,6 +5,7 @@
#include "string-list.h"
#include "chdir-notify.h"
#include "promisor-remote.h"
+#include "quote.h"
static int inside_git_dir = -1;
static int inside_work_tree = -1;
@@ -1090,6 +1091,42 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
}
}
+struct safe_directory_data {
+ const char *path;
+ int is_safe;
+};
+
+static int safe_directory_cb(const char *key, const char *value, void *d)
+{
+ struct safe_directory_data *data = d;
+
+ if (!value || !*value)
+ data->is_safe = 0;
+ else {
+ const char *interpolated = NULL;
+
+ if (!git_config_pathname(&interpolated, key, value) &&
+ !fspathcmp(data->path, interpolated ? interpolated : value))
+ data->is_safe = 1;
+
+ free((char *)interpolated);
+ }
+
+ return 0;
+}
+
+static int ensure_valid_ownership(const char *path)
+{
+ struct safe_directory_data data = { .path = path };
+
+ if (is_path_owned_by_current_user(path))
+ return 1;
+
+ read_very_early_config(safe_directory_cb, &data);
+
+ return data.is_safe;
+}
+
enum discovery_result {
GIT_DIR_NONE = 0,
GIT_DIR_EXPLICIT,
@@ -1098,7 +1135,8 @@ enum discovery_result {
/* these are errors */
GIT_DIR_HIT_CEILING = -1,
GIT_DIR_HIT_MOUNT_POINT = -2,
- GIT_DIR_INVALID_GITFILE = -3
+ GIT_DIR_INVALID_GITFILE = -3,
+ GIT_DIR_INVALID_OWNERSHIP = -4
};
/*
@@ -1188,11 +1226,15 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
}
strbuf_setlen(dir, offset);
if (gitdirenv) {
+ if (!ensure_valid_ownership(dir->buf))
+ return GIT_DIR_INVALID_OWNERSHIP;
strbuf_addstr(gitdir, gitdirenv);
return GIT_DIR_DISCOVERED;
}
if (is_git_directory(dir->buf)) {
+ if (!ensure_valid_ownership(dir->buf))
+ return GIT_DIR_INVALID_OWNERSHIP;
strbuf_addstr(gitdir, ".");
return GIT_DIR_BARE;
}
@@ -1324,6 +1366,19 @@ const char *setup_git_directory_gently(int *nongit_ok)
dir.buf);
*nongit_ok = 1;
break;
+ case GIT_DIR_INVALID_OWNERSHIP:
+ if (!nongit_ok) {
+ struct strbuf quoted = STRBUF_INIT;
+
+ sq_quote_buf_pretty(&quoted, dir.buf);
+ die(_("unsafe repository ('%s' is owned by someone else)\n"
+ "To add an exception for this directory, call:\n"
+ "\n"
+ "\tgit config --global --add safe.directory %s"),
+ dir.buf, quoted.buf);
+ }
+ *nongit_ok = 1;
+ break;
case GIT_DIR_NONE:
/*
* As a safeguard against setup_git_directory_gently_1 returning