submodule--helper: fix potential NULL-dereference

Don't dereference NULL 'path' if it was never assigned. Also protect against an empty --path argument. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Mar 31, 2016 at 14:04 UTC 3c0663e16630ddfd9f4c2e46e52c9984a03b888d
1 file changed +4 -4
builtin/submodule--helper.c
+4 -4
@@ -194,6 +194,9 @@ static int module_clone(int argc, const char **argv, const char *prefix)
194 argc = parse_options(argc, argv, prefix, module_clone_options,
195 git_submodule_helper_usage, 0);
196
197 + if (!path || !*path)
198 + die(_("submodule--helper: unspecified or empty --path"));
199 +
200 strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
201 sm_gitdir = strbuf_detach(&sb, NULL);
202
@@ -215,10 +218,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
218 if (safe_create_leading_directories_const(path) < 0)
219 die(_("could not create directory '%s'"), path);
220
218 - if (path && *path)
219 - strbuf_addf(&sb, "%s/.git", path);
220 - else
221 - strbuf_addstr(&sb, ".git");
221 + strbuf_addf(&sb, "%s/.git", path);
222
223 if (safe_create_leading_directories_const(sb.buf) < 0)
224 die(_("could not create leading directories of '%s'"), sb.buf);