From 3ea78f241fb0c77822d75211752b4a1d4f299ed7 Mon Sep 17 00:00:00 2001 From: "Yury G. Kudryashov" Date: Mon, 9 Feb 2015 19:40:22 +0300 Subject: [PATCH 1/2] Add test for include.path inside included config It fails at least on my computer, though it may depend on some unpredictable factors (say, will realloc() extend the memory segment in place, or it will allocate new memory). --- tests/config/include.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/config/include.c b/tests/config/include.c index 0a931342a..8232af489 100644 --- a/tests/config/include.c +++ b/tests/config/include.c @@ -102,3 +102,25 @@ void test_config_include__missing(void) git_config_free(cfg); } + +#define replicate10(s) s s s s s s s s s s +void test_config_include__depth2(void) +{ + git_config *cfg; + const char *str; + const char *content = "[include]\n" replicate10(replicate10("path=bottom\n")); + + cl_git_mkfile("top-level", "[include]\npath = middle\n[foo]\nbar = baz"); + cl_git_mkfile("middle", content); + cl_git_mkfile("bottom", "[foo]\nbar2 = baz2"); + + cl_git_pass(git_config_open_ondisk(&cfg, "top-level")); + + cl_git_pass(git_config_get_string(&str, cfg, "foo.bar")); + cl_assert_equal_s(str, "baz"); + + cl_git_pass(git_config_get_string(&str, cfg, "foo.bar2")); + cl_assert_equal_s(str, "baz2"); + + git_config_free(cfg); +} From 1713653883c3dfd199a18b51a1e2b37def183101 Mon Sep 17 00:00:00 2001 From: "Yury G. Kudryashov" Date: Thu, 5 Feb 2015 23:39:59 +0300 Subject: [PATCH 2/2] Reinit `reader` pointer after reading included config file Fixes #2869. If included file includes more files, it may reallocate cfg_file->readers, hence invalidate not only `r` pointer, but `result` pointer as well. --- src/config_file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config_file.c b/src/config_file.c index 4f041e7e3..268cced09 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1284,6 +1284,7 @@ static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct r if (result == 0) { result = config_parse(values, cfg_file, r, level, depth+1); r = git_array_get(cfg_file->readers, index); + reader = git_array_get(cfg_file->readers, reader_idx); } else if (result == GIT_ENOTFOUND) { giterr_clear();