mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <>
To: Jeff King <>
Cc: "Érico Rolim" <>,
Subject: Re* [BUG] segmentation fault in git-diff
Date: Thu, 09 Apr 2020 17:03:45 -0700	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <> (Jeff King's message of "Thu, 9 Apr 2020 19:41:52 -0400")

Jeff King <> writes:

> But there are a bunch of other commits around the same time replacing
> the_repository, and it seems like an easy mistake to make. Perhaps we
> should rename the "refs" member of "struct repository" to something more
> clearly private, which would force callers to use the access method.

Here is the final version that I am going to apply and merge to
'jch' branch.  This is an ancient regression in Git timescale, so
its fix is not all that urgent, though.

-- >8 --
Subject: [PATCH] sha1-name: do not assume that the ref store is initialized

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 <>
Signed-off-by: Junio C Hamano <>
 sha1-name.c                   | 2 +-
 t/ | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/sha1-name.c b/sha1-name.c
index d9050776dd..3aba62938f 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -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);
 			return get_oid_oneline(repo, name + 2, oid, list);
diff --git a/t/ b/t/
index 4c8f3b8e1b..6cdbe4747a 100755
--- a/t/
+++ b/t/
@@ -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' '

  reply	other threads:[~2020-04-10  0:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 22:22 [BUG] segmentation fault in git-diff Érico Rolim
2020-04-09 22:45 ` Junio C Hamano
2020-04-09 22:47   ` Junio C Hamano
2020-04-09 22:57     ` Junio C Hamano
2020-04-09 23:37       ` Junio C Hamano
2020-04-09 23:41       ` Jeff King
2020-04-10  0:03         ` Junio C Hamano [this message]
2020-04-10  1:42           ` Re* " Érico Rolim
2020-04-10  3:04           ` Jeff King
2020-04-10  5:39             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).