git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Michael Schubert <mschub@elegosoft.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Shawn Pearce <spearce@spearce.org>,
	git@vger.kernel.org
Subject: Re: [PATCH] Verify Content-Type from smart HTTP servers
Date: Wed, 6 Feb 2013 05:39:52 -0500	[thread overview]
Message-ID: <20130206103952.GA5267@sigill.intra.peff.net> (raw)
In-Reply-To: <51122F69.9060704@elegosoft.com>

On Wed, Feb 06, 2013 at 11:24:41AM +0100, Michael Schubert wrote:

> On 01/31/2013 11:09 PM, Junio C Hamano wrote:
> 
> >  
> > -static int http_request_reauth(const char *url, void *result, int target,
> > +static int http_request_reauth(const char *url,
> > +			       struct strbuf *type,
> > +			       void *result, int target,
> >  			       int options)
> >  {
> > -	int ret = http_request(url, result, target, options);
> > +	int ret = http_request(url, type, result, target, options);
> >  	if (ret != HTTP_REAUTH)
> >  		return ret;
> > -	return http_request(url, result, target, options);
> > +	return http_request(url, type, result, target, options);
> >  }
> 
> This needs something like
> 
> diff --git a/http.c b/http.c
> index d868d8b..da43be3 100644
> --- a/http.c
> +++ b/http.c
> @@ -860,6 +860,8 @@ static int http_request_reauth(const char *url,
>         int ret = http_request(url, type, result, target, options);
>         if (ret != HTTP_REAUTH)
>                 return ret;
> +       if (type)
> +               strbuf_reset(type);
>         return http_request(url, type, result, target, options);
>  }
> 
> on top. Otherwise we get
> 
> "text/plainapplication/x-git-receive-pack-advertisement"
> 
> when doing HTTP auth.

Good catch. It probably makes sense to put it in http_request, so that
we also protect against any existing cruft from the callers of
http_get_*, like:

-- >8 --
Subject: [PATCH] http_request: reset "type" strbuf before adding

Callers may pass us a strbuf which we use to record the
content-type of the response. However, we simply appended to
it rather than overwriting its contents, meaning that cruft
in the strbuf gave us a bogus type. E.g., the multiple
requests triggered by http_request could yield a type like
"text/plainapplication/x-git-receive-pack-advertisement".

Reported-by: Michael Schubert <mschub@elegosoft.com>
Signed-off-by: Jeff King <peff@peff.net>
---
Is it worth having a strbuf_set* family of functions to match the
strbuf_add*? We seem to have these sorts of errors with strbuf from time
to time, and I wonder if that would make it easier (and more readable)
to do the right thing.

 http.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/http.c b/http.c
index d868d8b..d9d1aad 100644
--- a/http.c
+++ b/http.c
@@ -841,6 +841,7 @@ static int http_request(const char *url, struct strbuf *type,
 
 	if (type) {
 		char *t;
+		strbuf_reset(type);
 		curl_easy_getinfo(slot->curl, CURLINFO_CONTENT_TYPE, &t);
 		if (t)
 			strbuf_addstr(type, t);
-- 
1.8.1.2.11.g1a2f572

  reply	other threads:[~2013-02-06 10:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-31 22:09 [PATCH] Verify Content-Type from smart HTTP servers Junio C Hamano
2013-02-01  8:52 ` Jeff King
2013-02-01 18:09   ` Junio C Hamano
2013-02-01 18:58     ` Jeff King
2013-02-04  7:17       ` Junio C Hamano
2013-02-04  8:38         ` Jeff King
2013-02-04 23:49           ` Shawn Pearce
2013-02-05  0:21             ` Junio C Hamano
2013-02-06 10:24 ` Michael Schubert
2013-02-06 10:39   ` Jeff King [this message]
2013-02-06 15:56     ` Junio C Hamano
2013-02-06 22:47       ` Jeff King
     [not found] <1359666943-13316-1-git-send-email-spearce@spearce.org>
     [not found] ` <7vd2wlf1zf.fsf@alter.siamese.dyndns.org>
2013-01-31 22:36   ` Shawn Pearce

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=20130206103952.GA5267@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mschub@elegosoft.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;
as well as URLs for NNTP newsgroup(s).