Skip to content

Commit d1409f4

Browse files
wilshipleypks-t
authored andcommitted
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.
1 parent 27cb4e0 commit d1409f4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/config_file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c
111111
if (!git_path_exists(b->file.path))
112112
return 0;
113113

114+
/*
115+
* git silently ignores configuration files that are not
116+
* readable. We emulate that behavior. This is particularly
117+
* important for sandboxed applications on macOS where the
118+
* git configuration files may not be readable.
119+
*/
120+
if (p_access(b->file.path, R_OK) < 0)
121+
return GIT_ENOTFOUND;
122+
114123
if (res < 0 || (res = config_file_read(b->entries, repo, &b->file, level, 0)) < 0) {
115124
git_config_entries_free(b->entries);
116125
b->entries = NULL;

0 commit comments

Comments
 (0)