Skip to content

Commit d06d422

Browse files
committed
config_file: properly ignore includes without "path" value
In case a configuration includes a key "include.path=" without any value, the generated configuration entry will have its value set to `NULL`. This is unexpected by the logic handling includes, and as soon as we try to calculate the included path we will unconditionally dereference that `NULL` pointer and thus segfault. Fix the issue by returning early in both `parse_include` and `parse_conditional_include` in case where the `file` argument is `NULL`. Add a test to avoid future regression. The issue has been found by the oss-fuzz project, issue 10810.
1 parent bf662f7 commit d06d422

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/config_file.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ static int parse_include(git_config_parser *reader,
664664
char *dir;
665665
int result;
666666

667+
if (!file)
668+
return 0;
669+
667670
if ((result = git_path_dirname_r(&path, reader->file->path)) < 0)
668671
return result;
669672

@@ -765,7 +768,7 @@ static int parse_conditional_include(git_config_parser *reader,
765768
size_t i;
766769
int error = 0, matches;
767770

768-
if (!parse_data->repo)
771+
if (!parse_data->repo || !file)
769772
return 0;
770773

771774
condition = git__substrdup(section + strlen("includeIf."),

tests/config/include.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ void test_config_include__depth(void)
8787
cl_git_pass(p_unlink("b"));
8888
}
8989

90+
void test_config_include__empty_path_sanely_handled(void)
91+
{
92+
cl_git_mkfile("a", "[include]\npath");
93+
cl_git_pass(git_config_open_ondisk(&cfg, "a"));
94+
cl_git_pass(git_config_get_string_buf(&buf, cfg, "include.path"));
95+
cl_assert_equal_s("", git_buf_cstr(&buf));
96+
97+
cl_git_pass(p_unlink("a"));
98+
}
99+
90100
void test_config_include__missing(void)
91101
{
92102
cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");

0 commit comments

Comments
 (0)