summaryrefslogtreecommitdiff
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2016-03-31 21:04:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-03-31 22:19:01 (GMT)
commit3c0663e16630ddfd9f4c2e46e52c9984a03b888d (patch)
tree6023f7fdc3ca263efa1c785d4297cfc758a486c4 /builtin/submodule--helper.c
parent3fea121df31c108ee9c52fd888a90d68a3bbb2b2 (diff)
downloadgit-3c0663e16630ddfd9f4c2e46e52c9984a03b888d.zip
git-3c0663e16630ddfd9f4c2e46e52c9984a03b888d.tar.gz
git-3c0663e16630ddfd9f4c2e46e52c9984a03b888d.tar.bz2
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>
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index f4c3eff..4f0b002 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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,
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);
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)
die(_("could not create directory '%s'"), path);
- if (path && *path)
- strbuf_addf(&sb, "%s/.git", path);
- else
- strbuf_addstr(&sb, ".git");
+ strbuf_addf(&sb, "%s/.git", path);
if (safe_create_leading_directories_const(sb.buf) < 0)
die(_("could not create leading directories of '%s'"), sb.buf);