From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Érico Rolim" <erico.erc@gmail.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: [BUG] segmentation fault in git-diff
Date: Thu, 09 Apr 2020 16:37:15 -0700 [thread overview]
Message-ID: <xmqqzhbkkz84.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <xmqq4ktsmfnn.fsf@gitster.c.googlers.com> (Junio C. Hamano's message of "Thu, 09 Apr 2020 15:57:00 -0700")
The problem bisects down to c931ba4e (sha1-name.c: remove the_repo
from handle_one_ref(), 2019-04-16), which did this:
- for_each_ref(handle_one_ref, &list);
- head_ref(handle_one_ref, &list);
+ 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);
The old code used the helper for_each_ref(). This is a thin wrapper
around refs_for_each_ref() and allows the default repository object
to be used implicitly by the caller. It is understandable that the
code wanted to work on arbitrary repository object, and replaced the
for_each_ref() helper with refs_for_each_ref() helper that takes any
ref store object.
But there is a small mistake. for_each_ref() makes sure that the
ref store is initialized; the new code blindly assumes it has
already been initialized.
int for_each_ref(each_ref_fn fn, void *cb_data)
{
return refs_for_each_ref(get_main_ref_store(the_repository), fn, cb_data);
}
So, I think the fix is simple. With the attached one liner on top
of c931ba4e (sha1-name.c: remove the_repo from handle_one_ref(),
2019-04-16),
$ git rev-parse :/any/path/
no longer segfaults. I think it would also work just fine when
merged to more modern codebase, but I haven't tried it (yet).
sha1-name.c | 2 +-
1 file changed, 1 insertion(+), 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);
commit_list_sort_by_date(&list);
return get_oid_oneline(repo, name + 2, oid, list);
next prev parent reply other threads:[~2020-04-09 23:37 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 [this message]
2020-04-09 23:41 ` Jeff King
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqzhbkkz84.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=erico.erc@gmail.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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
https://80x24.org/mirrors/git.git
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).