From: Mike Hommey <mh@glandium.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Nick Hengeveld <nickh@reactrix.com>
Subject: Re: [PATCH 2/4] Use strbuf in http code
Date: Sun, 9 Dec 2007 19:24:08 +0100 [thread overview]
Message-ID: <20071209182408.GA9427@glandium.org> (raw)
In-Reply-To: <7vy7c3pwek.fsf@gitster.siamese.dyndns.org>
On Sun, Dec 09, 2007 at 10:15:15AM -0800, Junio C Hamano wrote:
> Mike Hommey <mh@glandium.org> writes:
>
> > Also, replace whitespaces with tabs in some places
> >
> > Signed-off-by: Mike Hommey <mh@glandium.org>
> > ---
> >
> > While testing this, I noticed 3 things:
> > - CURL_MULTI makes the code very racy
> > - a lot of the code doesn't do anything useful without CURL_MULTI
> > - the code is redundant
>
> Yeah, there does seem to be a lot of duplicated code that does common
> setup with slightly different request string.
>
> > @@ -1115,16 +1109,11 @@ static char *quote_ref_url(const char *base, const char *ref)
> >
> > int fetch_ref(char *ref, unsigned char *sha1)
> > {
> > - char *url;
> > - char hex[42];
> > - struct buffer buffer;
> > + char *url;
> > + struct strbuf buffer = STRBUF_INIT;
> > char *base = remote->url;
> > struct active_request_slot *slot;
> > struct slot_results results;
> > - buffer.size = 41;
> > - buffer.posn = 0;
> > - buffer.buffer = hex;
> > - hex[41] = '\0';
> >
> > url = quote_ref_url(base, ref);
> > slot = get_active_slot();
> > @@ -1142,9 +1131,9 @@ int fetch_ref(char *ref, unsigned char *sha1)
> > return error("Unable to start request");
> > }
> >
> > - hex[40] = '\0';
> > - get_sha1_hex(hex, sha1);
> > - return 0;
> > + buffer.buf[40] = '\0';
> > + get_sha1_hex(buffer.buf, sha1);
> > + return 0;
> > }
>
> A conversion like this is worrysome and needs to be rethought I think.
>
> At least with the old code, we knew hex[40] was a safe location to make
> assignment to, even though we did not check if what it contained made
> sense --- the other end might have had a garbage in that URL (but the
> caller hopefully would be responsible for noticing that). But with your
> change, I do not think you have that guarantee. fwrite_buffer() may
> have extended the buffer using strbuf API, but it may have received less
> than what you are expecting, in which case you may not have buf[40]
> touchable for you, no?
>
> I at the same time think the original code is buggy. It initializes
> buffer.buffer to the on-stack storage hex[], but lets fwrite_buffer() to
> call xrealloc() on it.
Both codes are also buggy in case the ref is a symbolic ref, and that
happens. I got bitten by this while testing.
Considering the assumption being made that refs are all properly filled
with sha1s, both codes are mostly equally bad.
Fixing the issue would obviously be the subject for another patch.
Mike
next prev parent reply other threads:[~2007-12-09 18:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-09 17:04 [PATCH 1/4] Cleanup variables in http.[ch] Mike Hommey
2007-12-09 17:04 ` [PATCH 2/4] Use strbuf in http code Mike Hommey
2007-12-09 17:04 ` [PATCH 3/4] Move the file read logic to read_patch_file() in builtin-apply.c Mike Hommey
2007-12-09 17:05 ` [PATCH 4/4] Add support for URLs to git-apply Mike Hommey
2007-12-10 9:06 ` [Replacement PATCH " Mike Hommey
2007-12-09 18:27 ` [PATCH 3/4] Move the file read logic to read_patch_file() in builtin-apply.c Junio C Hamano
2007-12-09 18:15 ` [PATCH 2/4] Use strbuf in http code Junio C Hamano
2007-12-09 18:24 ` Mike Hommey [this message]
2007-12-09 18:36 ` Junio C Hamano
2007-12-09 19:30 ` [Resend PATCH " Mike Hommey
2007-12-11 6:04 ` Junio C Hamano
2007-12-11 6:16 ` Mike Hommey
2007-12-11 6:25 ` [Replacement " Mike Hommey
2007-12-09 17:17 ` [PATCH] git-send-email.perl: Really add angle brackets to In-Reply-To if necessary Mike Hommey
2007-12-09 17:38 ` Mike Hommey
2007-12-09 18:09 ` Junio C Hamano
2007-12-09 18:14 ` Mike Hommey
2007-12-09 18:21 ` David Kastrup
2007-12-09 18:53 ` Randal L. Schwartz
2007-12-09 19:46 ` David Kastrup
2007-12-09 19:51 ` Randal L. Schwartz
2007-12-09 19:58 ` [Resend PATCH] " Mike Hommey
2007-12-09 18:21 ` [PATCH 1/4] Cleanup variables in http.[ch] 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071209182408.GA9427@glandium.org \
--to=mh@glandium.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=nickh@reactrix.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.
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 NNTP newsgroup(s).