]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sha1-name: do not assume that the ref store is initialized
authorJunio C Hamano <gitster@pobox.com>
Fri, 10 Apr 2020 00:03:45 +0000 (17:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Apr 2020 00:22:20 +0000 (17:22 -0700)
c931ba4e (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 <erico.erc@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1-name.c
t/t4208-log-magic-pathspec.sh

index d9050776dde740d3d81748953d739ca4e076522e..3aba62938f9f651f1b959866cfa0658d777e680d 100644 (file)
@@ -1771,7 +1771,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 
                        cb.repo = repo;
                        cb.list = &list;
-                       refs_for_each_ref(repo->refs, handle_one_ref, &cb);
+                       refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);
                        refs_head_ref(repo->refs, handle_one_ref, &cb);
                        commit_list_sort_by_date(&list);
                        return get_oid_oneline(repo, name + 2, oid, list);
index 4c8f3b8e1bdd084a6407d76ff26cff0048e90bdf..6cdbe4747aa837376fd01c94420beb1bd1bb6d56 100755 (executable)
@@ -55,6 +55,10 @@ test_expect_success '"git log -- :/a" should not be ambiguous' '
        git log -- :/a
 '
 
+test_expect_success '"git log :/any/path/" should not segfault' '
+       test_must_fail git log :/any/path/
+'
+
 # This differs from the ":/a" check above in that :/in looks like a pathspec,
 # but doesn't match an actual file.
 test_expect_success '"git log :/in" should not be ambiguous' '