From: Junio C Hamano Date: Mon, 1 May 2017 05:14:43 +0000 (+0900) Subject: Merge branch 'jk/submodule-init-segv-fix' X-Git-Tag: v2.13.0-rc2~10 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/d92dbf1934faad614c31482446d5f32fb9322470?hp=b0f89870ea54b86fb7935f90605d329533849b33 Merge branch 'jk/submodule-init-segv-fix' Fix a segv in 'submodule init' when url is not given for a submodule. * jk/submodule-init-segv-fix: submodule_init: die cleanly on submodules without url defined --- diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 36e4231821..566a5b6a6f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -376,12 +376,12 @@ static void init_submodule(const char *path, const char *prefix, int quiet) strbuf_reset(&sb); strbuf_addf(&sb, "submodule.%s.url", sub->name); if (git_config_get_string(sb.buf, &url)) { - url = xstrdup(sub->url); - - if (!url) + if (!sub->url) die(_("No url found for submodule path '%s' in .gitmodules"), displaypath); + url = xstrdup(sub->url); + /* Possibly a url relative to parent */ if (starts_with_dot_dot_slash(url) || starts_with_dot_slash(url)) { diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index c2706fe472..1b8f1dbd3a 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -38,6 +38,14 @@ test_expect_success 'submodule update aborts on missing .gitmodules file' ' test_i18ngrep "Submodule path .sub. not initialized" actual ' +test_expect_success 'submodule update aborts on missing gitmodules url' ' + test_when_finished "git update-index --remove sub" && + git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && + test_when_finished "rm -f .gitmodules" && + git config -f .gitmodules submodule.s.path sub && + test_must_fail git submodule init +' + test_expect_success 'configuration parsing' ' test_when_finished "rm -f .gitmodules" && cat >.gitmodules <<-\EOF &&