From: Alex Riesen <raa.lkml@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git Mailing List <git@vger.kernel.org>,
"Shawn O. Pearce" <spearce@spearce.org>
Subject: Re: [PATCH] Fix mkpath abuse in dwim_ref/sha1_name.c
Date: Wed, 15 Oct 2008 08:20:40 +0200 [thread overview]
Message-ID: <20081015062039.GA3775@blimp.localdomain> (raw)
In-Reply-To: <7viqru6a1r.fsf@gitster.siamese.dyndns.org>
Junio C Hamano, Wed, Oct 15, 2008 01:17:52 +0200:
> "Alex Riesen" <raa.lkml@gmail.com> writes:
> >
> > Otherwise the function sometimes fail to resolve obviously correct refnames,
> > because the string data pointed to by "ref" argument were reused.
> >
> But your patch instead rewrites the computation of str2 by bypassing the
> call to "another_function_that_uses_get_pathname()" and duplicating its
> logic, which I do not think is a viable approach in the longer term.
There is not enough logic to bypass there. It's just a dumb sprintf!
I actually saved a useless call (two, if automatic inlining
optimization doesn't work).
> > diff --git a/sha1_name.c b/sha1_name.c
> > index 41b6809..b5b53bf 100644
> > --- a/sha1_name.c
> > +++ b/sha1_name.c
> > @@ -242,6 +242,7 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
> > {
> > const char **p, *r;
> > int refs_found = 0;
> > + char fullref[PATH_MAX];
> >
> > *ref = NULL;
> > for (p = ref_rev_parse_rules; *p; p++) {
> > @@ -249,7 +250,8 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
> > unsigned char *this_result;
> >
> > this_result = refs_found ? sha1_from_ref : sha1;
> > - r = resolve_ref(mkpath(*p, len, str), this_result, 1, NULL);
> > + snprintf(fullref, sizeof(fullref), *p, len, str);
> > + r = resolve_ref(fullref, this_result, 1, NULL);
> > if (r) {
> > if (!refs_found++)
> > *ref = xstrdup(r);
>
> I suspect that I am grossly misleading the code, but I wonder why this xstrdup()
> is not protecting us from the reusing of "the string data pointed to by
> "ref" argument". Are you fixing the overwriting of the string pointed to
> by "str" argument instead?
Yes, I mistyped. xstrdup's called after the breakage happened.
> What specific call chain has this breakage you found?
That's up to this function from builtin_rev_parse and resolve_ref
we're about to call.
next prev parent reply other threads:[~2008-10-15 6:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-14 16:23 [PATCH] Fix mkpath abuse in dwim_ref/sha1_name.c Alex Riesen
2008-10-14 23:17 ` Junio C Hamano
2008-10-15 6:20 ` Alex Riesen [this message]
2008-10-15 21:22 ` Junio C Hamano
2008-10-16 6:21 ` Alex Riesen
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081015062039.GA3775@blimp.localdomain \
--to=raa.lkml@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox