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

On Thu, Apr 09, 2020 at 03:57:00PM -0700, Junio C Hamano wrote:

> $ git checkout v2.22.0 && make && ./git-rev-parse :/any/path/
> segfaults, while
> $ git checkout v2.21.0 && make && ./git-rev-parse :/any/path/
> is OK.  We should be able to bisect this fairly straightforward
> between these two.

Indeed. The culprit is c931ba4e78 (sha1-name.c: remove the_repo from
handle_one_ref(), 2019-04-16), which swapped out for_each_ref() for
refs_for_each_ref(repo->refs). But it misses the access method for
repo->refs which lazy-initializes the pointer.

So the immediate fix is:

diff --git a/sha1-name.c b/sha1-name.c
index d9050776dd..c679e246cd 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1771,8 +1771,8 @@ 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_head_ref(repo->refs, handle_one_ref, &cb);
+			refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);
+			refs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb);
 			return get_oid_oneline(repo, name + 2, oid, list);

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.

I also wonder if there should be a repo_for_each_ref() which does it for
us, though I guess there a bazillion variants (like head_ref()) that
would need similar treatment. Asking each caller to use
get_main_ref_store() isn't too bad.


  parent reply	other threads:[~2020-04-09 23:41 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 [this message]
2020-04-10  0:03         ` Re* " Junio C Hamano
2020-04-10  1:42           ` É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).