Skip to content

Commit 3c0663e

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3fea121 commit 3c0663e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

builtin/submodule--helper.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ static int module_clone(int argc, const char **argv, const char *prefix)
194194
argc = parse_options(argc, argv, prefix, module_clone_options,
195195
git_submodule_helper_usage, 0);
196196

197+
if (!path || !*path)
198+
die(_("submodule--helper: unspecified or empty --path"));
199+
197200
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
198201
sm_gitdir = strbuf_detach(&sb, NULL);
199202

@@ -215,10 +218,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
215218
if (safe_create_leading_directories_const(path) < 0)
216219
die(_("could not create directory '%s'"), path);
217220

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);
222222

223223
if (safe_create_leading_directories_const(sb.buf) < 0)
224224
die(_("could not create leading directories of '%s'"), sb.buf);

0 commit comments

Comments
 (0)