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>
This commit is contained in:

committed by
Junio C Hamano

parent
3fea121df3
commit
3c0663e166
@ -194,6 +194,9 @@ static int module_clone(int argc, const char **argv, const char *prefix)
|
|||||||
argc = parse_options(argc, argv, prefix, module_clone_options,
|
argc = parse_options(argc, argv, prefix, module_clone_options,
|
||||||
git_submodule_helper_usage, 0);
|
git_submodule_helper_usage, 0);
|
||||||
|
|
||||||
|
if (!path || !*path)
|
||||||
|
die(_("submodule--helper: unspecified or empty --path"));
|
||||||
|
|
||||||
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
|
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
|
||||||
sm_gitdir = strbuf_detach(&sb, NULL);
|
sm_gitdir = strbuf_detach(&sb, NULL);
|
||||||
|
|
||||||
@ -215,10 +218,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
|
|||||||
if (safe_create_leading_directories_const(path) < 0)
|
if (safe_create_leading_directories_const(path) < 0)
|
||||||
die(_("could not create directory '%s'"), path);
|
die(_("could not create directory '%s'"), path);
|
||||||
|
|
||||||
if (path && *path)
|
strbuf_addf(&sb, "%s/.git", path);
|
||||||
strbuf_addf(&sb, "%s/.git", path);
|
|
||||||
else
|
|
||||||
strbuf_addstr(&sb, ".git");
|
|
||||||
|
|
||||||
if (safe_create_leading_directories_const(sb.buf) < 0)
|
if (safe_create_leading_directories_const(sb.buf) < 0)
|
||||||
die(_("could not create leading directories of '%s'"), sb.buf);
|
die(_("could not create leading directories of '%s'"), sb.buf);
|
||||||
|
Reference in New Issue
Block a user