зеркало из https://github.com/microsoft/git.git
get_oid: handle NULL repo->index
When get_oid() and its helpers see an index name like ":.gitmodules", they try to load the index on demand, like: if (repo->index->cache) repo_read_index(repo); However, that misses the case when "repo->index" itself is NULL; we'll segfault in the conditional. This never happens with the_repository; there we always point its index field to &the_index. But a submodule repository may have a NULL index field until somebody calls repo_read_index(). This bug is triggered by t7411, but it was hard to notice because it's in an expect_failure block. That test was added by2b1257e463
(t/helper: add test-submodule-nested-repo-config, 2018-10-25). Back then we had no easy way to access the .gitmodules blob of a submodule repo, so we expected (and got) an error message to that effect. Later,d9b8b8f896
(submodule-config.c: use repo_get_oid for reading .gitmodules, 2019-04-16) started looking in the correct repo, which is when we started triggering the segfault. With this fix, the test starts passing (once we clean it up as its comment instructs). Note that as far as I know, this bug could not be triggered outside of the test suite. It requires resolving an index name in a submodule, and all of the code paths (aside from test-tool) which do that either load the index themselves, or always pass the_repository. Ultimately it comes from3a7a698e93
(sha1-name.c: remove implicit dependency on the_index, 2019-01-12), which replaced a check of "the_index.cache" with "repo->index->cache". So even if there is another way to trigger it, it wouldn't affect any versions before then. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
ab15ad1a3b
Коммит
581d2fd9f2
|
@ -1837,7 +1837,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
|
|||
if (flags & GET_OID_RECORD_PATH)
|
||||
oc->path = xstrdup(cp);
|
||||
|
||||
if (!repo->index->cache)
|
||||
if (!repo->index || !repo->index->cache)
|
||||
repo_read_index(repo);
|
||||
pos = index_name_pos(repo->index, cp, namelen);
|
||||
if (pos < 0)
|
||||
|
|
|
@ -243,18 +243,14 @@ test_expect_success 'reading nested submodules config' '
|
|||
)
|
||||
'
|
||||
|
||||
# When this test eventually passes, before turning it into
|
||||
# test_expect_success, remember to replace the test_i18ngrep below with
|
||||
# a "test_must_be_empty warning" to be sure that the warning is actually
|
||||
# removed from the code.
|
||||
test_expect_failure 'reading nested submodules config when .gitmodules is not in the working tree' '
|
||||
test_expect_success 'reading nested submodules config when .gitmodules is not in the working tree' '
|
||||
test_when_finished "git -C super/submodule checkout .gitmodules" &&
|
||||
(cd super &&
|
||||
echo "./nested_submodule" >expect &&
|
||||
rm submodule/.gitmodules &&
|
||||
test-tool submodule-nested-repo-config \
|
||||
submodule submodule.nested_submodule.url >actual 2>warning &&
|
||||
test_i18ngrep "nested submodules without %s in the working tree are not supported yet" warning &&
|
||||
test_must_be_empty warning &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
|
Загрузка…
Ссылка в новой задаче