mirror of
https://github.com/git/git
synced 2024-10-03 23:29:36 +00:00
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
This commit is contained in:
commit
9cd234e646
|
@ -2024,14 +2024,17 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
|
|||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "submodule.%s.url", sub->name);
|
||||
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
|
||||
if (starts_with_dot_slash(sub->url) ||
|
||||
starts_with_dot_dot_slash(sub->url)) {
|
||||
if (sub->url && (starts_with_dot_slash(sub->url) ||
|
||||
starts_with_dot_dot_slash(sub->url))) {
|
||||
url = resolve_relative_url(sub->url, NULL, 0);
|
||||
need_free_url = 1;
|
||||
} else
|
||||
url = sub->url;
|
||||
}
|
||||
|
||||
if (!url)
|
||||
die(_("cannot clone submodule '%s' without a URL"), sub->name);
|
||||
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "%s/.git", ce->name);
|
||||
needs_cloning = !file_exists(sb.buf);
|
||||
|
|
|
@ -1351,6 +1351,22 @@ test_expect_success 'clone active submodule without submodule url set' '
|
|||
)
|
||||
'
|
||||
|
||||
test_expect_success 'update submodules without url set in .gitconfig' '
|
||||
test_when_finished "rm -rf multisuper_clone" &&
|
||||
git clone file://"$pwd"/multisuper multisuper_clone &&
|
||||
|
||||
git -C multisuper_clone submodule init &&
|
||||
for s in sub0 sub1 sub2 sub3
|
||||
do
|
||||
key=submodule.$s.url &&
|
||||
git -C multisuper_clone config --local --unset $key &&
|
||||
git -C multisuper_clone config --file .gitmodules --unset $key || return 1
|
||||
done &&
|
||||
|
||||
test_must_fail git -C multisuper_clone submodule update 2>err &&
|
||||
grep "cannot clone submodule .sub[0-3]. without a URL" err
|
||||
'
|
||||
|
||||
test_expect_success 'clone --recurse-submodules with a pathspec works' '
|
||||
test_when_finished "rm -rf multisuper_clone" &&
|
||||
cat >expected <<-\EOF &&
|
||||
|
|
Loading…
Reference in a new issue