diff options
author | Jeff King <peff@peff.net> | 2017-04-24 20:57:47 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-04-24 19:00:15 -0700 |
commit | 627fde102515a7807dba89acaa88cb053b38a44a (patch) | |
tree | 3a255ca92f07db454e523baff730b18941eae6a8 /builtin | |
parent | 0202c411edc25940cc381bf317badcdf67670be4 (diff) | |
download | git-627fde102515a7807dba89acaa88cb053b38a44a.tar.gz |
submodule_init: die cleanly on submodules without url definedjk/submodule-init-segv-fix
When we init a submodule, we try to die when it has no URL
defined:
url = xstrdup(sub->url);
if (!url)
die(...);
But that's clearly nonsense. xstrdup() will never return
NULL, and if sub->url is NULL, we'll segfault.
These two bits of code need to be flipped, so we check
sub->url before looking at it.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/submodule--helper.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 926d205162..b345689561 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -332,12 +332,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)) { |