avoid segfault on submodule.*.path set to an empty "true"
authorJharrod LaFon <jlafon@eyesopen.com>
Mon, 19 Aug 2013 16:26:56 +0000 (09:26 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Aug 2013 20:47:56 +0000 (13:47 -0700)
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 <jlafon@eyesopen.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
t/t7400-submodule-basic.sh
index 975bc87e48b33e70bd7c38e82b7f59e34bb81ca3..8f7515ed6644a22e6f860eac72b2897e636cdf3d 100644 (file)
@@ -134,6 +134,9 @@ int parse_submodule_config_option(const char *var, const char *value)
                return 0;
 
        if (!strcmp(key, "path")) {
+               if (!value)
+                       return config_error_nonbool(var);
+
                config = unsorted_string_list_lookup(&config_name_for_path, value);
                if (config)
                        free(config->util);
@@ -151,6 +154,9 @@ int parse_submodule_config_option(const char *var, const char *value)
        } else if (!strcmp(key, "ignore")) {
                char *name_cstr;
 
+               if (!value)
+                       return config_error_nonbool(var);
+
                if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
                    strcmp(value, "all") && strcmp(value, "none")) {
                        warning("Invalid parameter \"%s\" for config option \"submodule.%s.ignore\"", value, var);
index 2683cba7e3f0ba7fbb7ea1752a39a6068fc91718..0edf74c68f6907aedc8c863d573138c31e7110f2 100755 (executable)
@@ -18,6 +18,16 @@ test_expect_success 'setup - initial commit' '
        git branch initial
 '
 
+test_expect_success 'configuration parsing' '
+       test_when_finished "rm -f .gitmodules" &&
+       cat >.gitmodules <<-\EOF &&
+       [submodule "s"]
+               path
+               ignore
+       EOF
+       test_must_fail git status
+'
+
 test_expect_success 'setup - repository in init subdirectory' '
        mkdir init &&
        (