diff options
author | Patrick Steinhardt <ps@pks.im> | 2020-06-01 13:57:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 13:57:12 +0200 |
commit | 1bbdf15d30e70d4068cb2b520cf3adfc25135a4d (patch) | |
tree | bf8230e9c16edac4eb370a637a4cfdbe55eb7c0b | |
parent | 89ddd0fc740093d793a87452e0c707671710e1bf (diff) | |
parent | 9df69223b13f59032fd295124666c6a5627a450a (diff) | |
download | libgit2-1bbdf15d30e70d4068cb2b520cf3adfc25135a4d.tar.gz |
Merge pull request #5527 from libgit2/ethomson/config_unreadable
Handle unreadable configuration files
-rw-r--r-- | src/config_file.c | 9 | ||||
-rw-r--r-- | tests/config/read.c | 17 |
2 files changed, 26 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; diff --git a/tests/config/read.c b/tests/config/read.c index 008dfd9fc..ba97302f7 100644 --- a/tests/config/read.c +++ b/tests/config/read.c @@ -849,6 +849,23 @@ void test_config_read__invalid_quoted_third_section(void) git_config_free(cfg); } +void test_config_read__unreadable_file_ignored(void) +{ + git_buf buf = GIT_BUF_INIT; + git_config *cfg; + int ret; + + cl_set_cleanup(&clean_test_config, NULL); + cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"] var = value"); + cl_git_pass(p_chmod("./testconfig", 0)); + + ret = git_config_open_ondisk(&cfg, "./test/config"); + cl_assert(ret == 0 || ret == GIT_ENOTFOUND); + + git_config_free(cfg); + git_buf_dispose(&buf); +} + void test_config_read__single_line(void) { git_buf buf = GIT_BUF_INIT; |