From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Mantas Mikulėnas" <grawity@gmail.com>
Subject: Re: [PATCH] do_one_ref(): save and restore value of current_ref
Date: Fri, 19 Jul 2013 10:43:38 -0700 [thread overview]
Message-ID: <51E97ACA.40300@alum.mit.edu> (raw)
In-Reply-To: <7voba04ir8.fsf@alter.siamese.dyndns.org>
On 07/17/2013 09:03 PM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@alum.mit.edu> writes:
>
>> If do_one_ref() is called recursively, then the inner call should not
>> permanently overwrite the value stored in current_ref by the outer
>> call. Aside from the tiny optimization loss, peel_ref() expects the
>> value of current_ref not to change across a call to peel_entry(). But
>> in the presence of replace references that assumption could be
>> violated by a recursive call to do_one_ref:
>>
>> do_for_each_entry()
>> do_one_ref()
>> builtin/describe.c:get_name()
>> peel_ref()
>> peel_entry()
>> peel_object ()
>> deref_tag_noverify()
>> parse_object()
>> lookup_replace_object()
>> do_lookup_replace_object()
>> prepare_replace_object()
>> do_for_each_ref()
>> do_for_each_entry()
>> do_for_each_entry_in_dir()
>> do_one_ref()
>>
>> The inner call to do_one_ref() was unconditionally setting current_ref
>> to NULL when it was done, causing peel_ref() to perform an invalid
>> memory access.
>>
>> So change do_one_ref() to save the old value of current_ref before
>> overwriting it, and restore the old value afterward rather than
>> setting it to NULL.
>>
>> Reported by: Mantas Mikulėnas <grawity@gmail.com>
>>
>> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
>> ---
>
> Thanks.
>
> s/Reported by:/Reported-by:/ and lose the extra blank line after it?
ACK, sorry I got the notation wrong.
> I wonder if we can have an easy reproduction recipe in our tests.
I could reproduce the problem by following the recipe provided by Mantas
upthread (or at least something very close to it; I can't find the
script that I was using):
> git pack-refs --all --prune
> sed -i '/^[#^]/d' .git/packed-refs
> git replace -f HEAD $(git --no-replace-objects cat-file commit HEAD \
> | sed 's/@/@test/' | git hash-object --stdin -t commit -w)
> ~/src/git/git describe
It would be good to document this in the commit message, but I don't
think it is necessary to have a test for it in the test suite because I
don't think it is the kind of bug that will reappear.
I sent the patch shortly before leaving for a trip so I didn't have time
to make it as complete as I would have liked. But given that the
problem was already in master, and the fix is pretty simple, I wanted to
send the fix right away. When I have some time I can fix it up better,
or feel free to manhandle the patch and/or commit message yourself if
you prefer.
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
next prev parent reply other threads:[~2013-07-19 17:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-13 13:27 Segfault in `git describe` Mantas Mikulėnas
2013-07-15 13:03 ` Michael Haggerty
2013-07-15 13:31 ` Mantas Mikulėnas
2013-07-15 15:24 ` [PATCH] do_one_ref(): save and restore value of current_ref Michael Haggerty
2013-07-18 4:03 ` Junio C Hamano
2013-07-19 17:43 ` Michael Haggerty [this message]
2013-07-19 19:34 ` Junio C Hamano
2013-07-24 14:35 ` Michael Haggerty
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=51E97ACA.40300@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=grawity@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).