summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWil Shipley <wjs@delicious-monster.com>2020-05-06 19:57:07 -0700
committerEdward Thomson <ethomson@edwardthomson.com>2020-06-03 10:10:31 +0100
commitc0bf387ffc6914bbba3a77fac2d50f61bf7769d6 (patch)
treef137fb728f2a940aa7b9667f32af3cd162a95ae9
parentc229591e3285e57e74c24f9d939ffcabd0a5694f (diff)
downloadlibgit2-c0bf387ffc6914bbba3a77fac2d50f61bf7769d6.tar.gz
config: ignore unreadable configuration files
Modified `config_file_open()` so it returns 0 if the config file is not readable, which happens on global config files under macOS sandboxing (note that for some reason `access(F_OK)` DOES work with sandboxing, but it is lying). Without this read check sandboxed applications on macOS can not open any repository, because `config_file_read()` will return GIT_ERROR when it cannot read the global /Users/username/.gitconfig file, and the upper layers will just completely abort on GIT_ERROR when attempting to load the global config file, so no repositories can be opened.
-rw-r--r--src/config_file.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/config_file.c b/src/config_file.c
index c9e36493e..b1e002836 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -111,6 +111,15 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c
if (!git_path_exists(b->file.path))
return 0;
+ /*
+ * git silently ignores configuration files that are not
+ * readable. We emulate that behavior. This is particularly
+ * important for sandboxed applications on macOS where the
+ * git configuration files may not be readable.
+ */
+ if (p_access(b->file.path, R_OK) < 0)
+ return GIT_ENOTFOUND;
+
if (res < 0 || (res = config_file_read(b->entries, repo, &b->file, level, 0)) < 0) {
git_config_entries_free(b->entries);
b->entries = NULL;