Skip to content

Commit 4b05440

Browse files
jlafongitster
authored andcommitted
avoid segfault on submodule.*.path set to an empty "true"
Git fails due to a segmentation fault if a submodule path is empty. Here is an example .gitmodules that will cause a segmentation fault: [submodule "foo-module"] path url = http://host/repo.git $ git status Segmentation fault (core dumped) This is because the parsing of "submodule.*.path" is not prepared to see a value-less "true" and assumes that the value is always non-NULL (parsing of "ignore" has the same problem). Fix it by checking the NULL-ness of value and complain with config_error_nonbool(). Signed-off-by: Jharrod LaFon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f59bebb commit 4b05440

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

submodule.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ int parse_submodule_config_option(const char *var, const char *value)
134134
return 0;
135135

136136
if (!strcmp(key, "path")) {
137+
if (!value)
138+
return config_error_nonbool(var);
139+
137140
config = unsorted_string_list_lookup(&config_name_for_path, value);
138141
if (config)
139142
free(config->util);
@@ -151,6 +154,9 @@ int parse_submodule_config_option(const char *var, const char *value)
151154
} else if (!strcmp(key, "ignore")) {
152155
char *name_cstr;
153156

157+
if (!value)
158+
return config_error_nonbool(var);
159+
154160
if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
155161
strcmp(value, "all") && strcmp(value, "none")) {
156162
warning("Invalid parameter \"%s\" for config option \"submodule.%s.ignore\"", value, var);

t/t7400-submodule-basic.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ test_expect_success 'setup - initial commit' '
1818
git branch initial
1919
'
2020

21+
test_expect_success 'configuration parsing' '
22+
test_when_finished "rm -f .gitmodules" &&
23+
cat >.gitmodules <<-\EOF &&
24+
[submodule "s"]
25+
path
26+
ignore
27+
EOF
28+
test_must_fail git status
29+
'
30+
2131
test_expect_success 'setup - repository in init subdirectory' '
2232
mkdir init &&
2333
(

0 commit comments

Comments
 (0)