Skip to content

Commit 8f2bbe4

Browse files
jrngitster
authored andcommitted
config: exit on error accessing any config file
There is convenience in warning and moving on when somebody has a bogus permissions on /etc/gitconfig and cannot do anything about it. But the cost in predictability and security is too high --- when unreadable config files are skipped, it means an I/O error or permissions problem causes important configuration to be bypassed. For example, servers may depend on /etc/gitconfig to enforce security policy (setting transfer.fsckObjects or receive.deny*). Best to always error out when encountering trouble accessing a config file. This may add inconvenience in some cases: 1. You are inspecting somebody else's repo, and you do not have access to their .git/config file. Git typically dies in this case already since we cannot read core.repositoryFormatVersion, so the change should not be too noticeable. 2. You have used "sudo -u" or a similar tool to switch uid, and your environment still points Git at your original user's global config, which is not readable. In this case people really would be inconvenienced (they would rather see the harmless warning and continue the operation) but they can work around it by setting HOME appropriately after switching uids. 3. You do not have access to /etc/gitconfig due to a broken setup. In this case, erroring out is a good way to put pressure on the sysadmin to fix the setup. While they wait for a reply, users can set GIT_CONFIG_NOSYSTEM to true to keep Git working without complaint. After this patch, errors accessing the repository-local and systemwide config files and files requested in include directives cause Git to exit, just like errors accessing ~/.gitconfig. Explained-by: Jeff King <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8ef401 commit 8f2bbe4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

config.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
6060
path = buf.buf;
6161
}
6262

63-
if (!access_or_warn(path, R_OK)) {
63+
if (!access_or_die(path, R_OK)) {
6464
if (++inc->depth > MAX_INCLUDE_DEPTH)
6565
die(include_depth_advice, MAX_INCLUDE_DEPTH, path,
6666
cf && cf->name ? cf->name : "the command line");
@@ -939,7 +939,7 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
939939

940940
home_config_paths(&user_config, &xdg_config, "config");
941941

942-
if (git_config_system() && !access_or_warn(git_etc_gitconfig(), R_OK)) {
942+
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK)) {
943943
ret += git_config_from_file(fn, git_etc_gitconfig(),
944944
data);
945945
found += 1;
@@ -955,7 +955,7 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
955955
found += 1;
956956
}
957957

958-
if (repo_config && !access_or_warn(repo_config, R_OK)) {
958+
if (repo_config && !access_or_die(repo_config, R_OK)) {
959959
ret += git_config_from_file(fn, repo_config, data);
960960
found += 1;
961961
}

0 commit comments

Comments
 (0)