diff options
author | Wil Shipley <wjs@delicious-monster.com> | 2020-05-06 19:57:07 -0700 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2020-06-01 13:21:29 +0200 |
commit | d1409f48e3e9c1d1494a4c02979ca381eb2298cf (patch) | |
tree | aab57072c50c20956e36f3325620fc2002bae49e | |
parent | 27cb4e0ec193aa5430d1a32fd90b5dc2d86f5fe1 (diff) | |
download | libgit2-d1409f48e3e9c1d1494a4c02979ca381eb2298cf.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.c | 9 |
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; |