Skip to content

Commit 74b6bda

Browse files
rscharfegitster
authored andcommitted
submodule: check for NULL return of get_submodule_ref_store()
If we can't find a ref store for a submodule then assume the latter is not initialized (or was removed). Print a status line accordingly instead of causing a segmentation fault by passing NULL as the first parameter of refs_head_ref(). Reported-by: Jeremy Feusi <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Initial-Test-By: Stefan Beller <[email protected]> Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d32eb83 commit 74b6bda

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

builtin/submodule--helper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,13 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
620620
displaypath);
621621
} else if (!(flags & OPT_CACHED)) {
622622
struct object_id oid;
623+
struct ref_store *refs = get_submodule_ref_store(path);
623624

624-
if (refs_head_ref(get_submodule_ref_store(path),
625-
handle_submodule_head_ref, &oid))
625+
if (!refs) {
626+
print_status(flags, '-', path, ce_oid, displaypath);
627+
goto cleanup;
628+
}
629+
if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
626630
die(_("could not resolve HEAD ref inside the "
627631
"submodule '%s'"), path);
628632

t/t7400-submodule-basic.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,21 @@ test_expect_success 'moving the superproject does not break submodules' '
821821
)
822822
'
823823

824+
test_expect_success 'moving the submodule does not break the superproject' '
825+
(
826+
cd addtest2 &&
827+
git submodule status
828+
) >actual &&
829+
sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
830+
mv addtest2/repo addtest2/repo.bak &&
831+
test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
832+
(
833+
cd addtest2 &&
834+
git submodule status
835+
) >actual &&
836+
test_cmp expect actual
837+
'
838+
824839
test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
825840
(
826841
cd addtest2 &&

0 commit comments

Comments
 (0)