Skip to content

Commit 9cd234e

Browse files
committed
Merge branch 'tb/submodule-null-deref-fix'
"git submodule" code trusted the data coming from the config (and the in-tree .gitmodules file) too much without validating, leading to NULL dereference if the user mucks with a repository (e.g. submodule.<name>.url is removed). This has been corrected. * tb/submodule-null-deref-fix: builtin/submodule--helper.c: handle missing submodule URLs
2 parents 098a191 + fbc806a commit 9cd234e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

builtin/submodule--helper.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,14 +2024,17 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
20242024
strbuf_reset(&sb);
20252025
strbuf_addf(&sb, "submodule.%s.url", sub->name);
20262026
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
2027-
if (starts_with_dot_slash(sub->url) ||
2028-
starts_with_dot_dot_slash(sub->url)) {
2027+
if (sub->url && (starts_with_dot_slash(sub->url) ||
2028+
starts_with_dot_dot_slash(sub->url))) {
20292029
url = resolve_relative_url(sub->url, NULL, 0);
20302030
need_free_url = 1;
20312031
} else
20322032
url = sub->url;
20332033
}
20342034

2035+
if (!url)
2036+
die(_("cannot clone submodule '%s' without a URL"), sub->name);
2037+
20352038
strbuf_reset(&sb);
20362039
strbuf_addf(&sb, "%s/.git", ce->name);
20372040
needs_cloning = !file_exists(sb.buf);

t/t7400-submodule-basic.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,22 @@ test_expect_success 'clone active submodule without submodule url set' '
13511351
)
13521352
'
13531353

1354+
test_expect_success 'update submodules without url set in .gitconfig' '
1355+
test_when_finished "rm -rf multisuper_clone" &&
1356+
git clone file://"$pwd"/multisuper multisuper_clone &&
1357+
1358+
git -C multisuper_clone submodule init &&
1359+
for s in sub0 sub1 sub2 sub3
1360+
do
1361+
key=submodule.$s.url &&
1362+
git -C multisuper_clone config --local --unset $key &&
1363+
git -C multisuper_clone config --file .gitmodules --unset $key || return 1
1364+
done &&
1365+
1366+
test_must_fail git -C multisuper_clone submodule update 2>err &&
1367+
grep "cannot clone submodule .sub[0-3]. without a URL" err
1368+
'
1369+
13541370
test_expect_success 'clone --recurse-submodules with a pathspec works' '
13551371
test_when_finished "rm -rf multisuper_clone" &&
13561372
cat >expected <<-\EOF &&

0 commit comments

Comments
 (0)