Skip to content

Commit 5ff4b92

Browse files
committed
sha1-name: do not assume that the ref store is initialized
c931ba4 (sha1-name.c: remove the_repo from handle_one_ref(), 2019-04-16) replaced the use of for_each_ref() helper, which works with the main ref store of the default repository instance, with refs_for_each_ref(), which can work on any ref store instance, by assuming that the repository instance the function is given has its ref store already initialized. But it is possible that nobody has initialized it, in which case, the code ends up dereferencing a NULL pointer. Reported-by: Érico Rolim <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c931ba4 commit 5ff4b92

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

sha1-name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
17711771

17721772
cb.repo = repo;
17731773
cb.list = &list;
1774-
refs_for_each_ref(repo->refs, handle_one_ref, &cb);
1774+
refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);
17751775
refs_head_ref(repo->refs, handle_one_ref, &cb);
17761776
commit_list_sort_by_date(&list);
17771777
return get_oid_oneline(repo, name + 2, oid, list);

t/t4208-log-magic-pathspec.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ test_expect_success '"git log -- :/a" should not be ambiguous' '
5555
git log -- :/a
5656
'
5757

58+
test_expect_success '"git log :/any/path/" should not segfault' '
59+
test_must_fail git log :/any/path/
60+
'
61+
5862
# This differs from the ":/a" check above in that :/in looks like a pathspec,
5963
# but doesn't match an actual file.
6064
test_expect_success '"git log :/in" should not be ambiguous' '

0 commit comments

Comments
 (0)