Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
84d6f439
Unverified
Commit
84d6f439
authored
Oct 05, 2018
by
Patrick Steinhardt
Committed by
GitHub
Oct 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4832 from pks-t/pks/config-includes-null-deref
config_file: properly ignore includes without "path" value
parents
b37a5954
d06d4220
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
3 deletions
+44
-3
src/config_file.c
+4
-1
tests/config/include.c
+40
-2
No files found.
src/config_file.c
View file @
84d6f439
...
...
@@ -664,6 +664,9 @@ static int parse_include(git_config_parser *reader,
char
*
dir
;
int
result
;
if
(
!
file
)
return
0
;
if
((
result
=
git_path_dirname_r
(
&
path
,
reader
->
file
->
path
))
<
0
)
return
result
;
...
...
@@ -765,7 +768,7 @@ static int parse_conditional_include(git_config_parser *reader,
size_t
i
;
int
error
=
0
,
matches
;
if
(
!
parse_data
->
repo
)
if
(
!
parse_data
->
repo
||
!
file
)
return
0
;
condition
=
git__substrdup
(
section
+
strlen
(
"includeIf."
),
...
...
tests/config/include.c
View file @
84d6f439
...
...
@@ -35,6 +35,8 @@ void test_config_include__absolute(void)
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar.baz"
));
cl_assert_equal_s
(
"huzzah"
,
git_buf_cstr
(
&
buf
));
cl_git_pass
(
p_unlink
(
"config-include-absolute"
));
}
void
test_config_include__homedir
(
void
)
...
...
@@ -48,6 +50,8 @@ void test_config_include__homedir(void)
cl_assert_equal_s
(
"huzzah"
,
git_buf_cstr
(
&
buf
));
cl_sandbox_set_search_path_defaults
();
cl_git_pass
(
p_unlink
(
"config-include-homedir"
));
}
/* We need to pretend that the variables were defined where the file was included */
...
...
@@ -66,6 +70,9 @@ void test_config_include__ordering(void)
git_buf_clear
(
&
buf
);
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar.baz"
));
cl_assert_equal_s
(
"huzzah"
,
git_buf_cstr
(
&
buf
));
cl_git_pass
(
p_unlink
(
"included"
));
cl_git_pass
(
p_unlink
(
"including"
));
}
/* We need to pretend that the variables were defined where the file was included */
...
...
@@ -76,8 +83,18 @@ void test_config_include__depth(void)
cl_git_fail
(
git_config_open_ondisk
(
&
cfg
,
"a"
));
p_unlink
(
"a"
);
p_unlink
(
"b"
);
cl_git_pass
(
p_unlink
(
"a"
));
cl_git_pass
(
p_unlink
(
"b"
));
}
void
test_config_include__empty_path_sanely_handled
(
void
)
{
cl_git_mkfile
(
"a"
,
"[include]
\n
path"
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"a"
));
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"include.path"
));
cl_assert_equal_s
(
""
,
git_buf_cstr
(
&
buf
));
cl_git_pass
(
p_unlink
(
"a"
));
}
void
test_config_include__missing
(
void
)
...
...
@@ -89,6 +106,8 @@ void test_config_include__missing(void)
cl_assert
(
giterr_last
()
==
NULL
);
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar"
));
cl_assert_equal_s
(
"baz"
,
git_buf_cstr
(
&
buf
));
cl_git_pass
(
p_unlink
(
"including"
));
}
void
test_config_include__missing_homedir
(
void
)
...
...
@@ -103,6 +122,7 @@ void test_config_include__missing_homedir(void)
cl_assert_equal_s
(
"baz"
,
git_buf_cstr
(
&
buf
));
cl_sandbox_set_search_path_defaults
();
cl_git_pass
(
p_unlink
(
"including"
));
}
#define replicate10(s) s s s s s s s s s s
...
...
@@ -122,6 +142,10 @@ void test_config_include__depth2(void)
git_buf_clear
(
&
buf
);
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar2"
));
cl_assert_equal_s
(
"baz2"
,
git_buf_cstr
(
&
buf
));
cl_git_pass
(
p_unlink
(
"top-level"
));
cl_git_pass
(
p_unlink
(
"middle"
));
cl_git_pass
(
p_unlink
(
"bottom"
));
}
void
test_config_include__removing_include_removes_values
(
void
)
...
...
@@ -132,6 +156,9 @@ void test_config_include__removing_include_removes_values(void)
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"top-level"
));
cl_git_mkfile
(
"top-level"
,
""
);
cl_git_fail
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar"
));
cl_git_pass
(
p_unlink
(
"top-level"
));
cl_git_pass
(
p_unlink
(
"included"
));
}
void
test_config_include__rewriting_include_refreshes_values
(
void
)
...
...
@@ -145,6 +172,10 @@ void test_config_include__rewriting_include_refreshes_values(void)
cl_git_fail
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar"
));
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"first.other"
));
cl_assert_equal_s
(
buf
.
ptr
,
"value"
);
cl_git_pass
(
p_unlink
(
"top-level"
));
cl_git_pass
(
p_unlink
(
"first"
));
cl_git_pass
(
p_unlink
(
"second"
));
}
void
test_config_include__included_variables_cannot_be_deleted
(
void
)
...
...
@@ -154,13 +185,20 @@ void test_config_include__included_variables_cannot_be_deleted(void)
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"top-level"
));
cl_git_fail
(
git_config_delete_entry
(
cfg
,
"foo.bar"
));
cl_git_pass
(
p_unlink
(
"top-level"
));
cl_git_pass
(
p_unlink
(
"included"
));
}
void
test_config_include__included_variables_cannot_be_modified
(
void
)
{
cl_git_mkfile
(
"top-level"
,
"[include]
\n
path = included
\n
"
);
cl_git_mkfile
(
"included"
,
"[foo]
\n
bar = value"
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"top-level"
));
cl_git_fail
(
git_config_set_string
(
cfg
,
"foo.bar"
,
"other-value"
));
cl_git_pass
(
p_unlink
(
"top-level"
));
cl_git_pass
(
p_unlink
(
"included"
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment