git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brandon Casey <bcasey@nvidia.com>
To: <git@vger.kernel.org>
Cc: <peff@peff.net>, <gitster@pobox.com>, Brandon Casey <drafnel@gmail.com>
Subject: [PATCH] http.c: don't rewrite the user:passwd string multiple times
Date: Mon, 17 Jun 2013 19:00:40 -0700	[thread overview]
Message-ID: <1371520840-24906-1-git-send-email-bcasey@nvidia.com> (raw)

From: Brandon Casey <drafnel@gmail.com>

Curl requires that we manage any strings that we pass to it as pointers.
So, we should not be overwriting this strbuf after we've passed it to
curl.

Additionally, it is unnecessary since we only prompt for the user name
and password once, so we end up overwriting the strbuf with the same
sequence of characters each time.  This is why in practice it has not
caused any problems for git's use of curl; the internal strbuf char
pointer does not change, and get's overwritten with the same string
each time.

But it's unnecessary and potentially dangerous, so let's avoid it.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
---
 http.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/http.c b/http.c
index 92aba59..6828269 100644
--- a/http.c
+++ b/http.c
@@ -228,8 +228,8 @@ static void init_curl_http_auth(CURL *result)
 #else
 	{
 		static struct strbuf up = STRBUF_INIT;
-		strbuf_reset(&up);
-		strbuf_addf(&up, "%s:%s",
+		if (!up.len)
+			strbuf_addf(&up, "%s:%s",
 			    http_auth.username, http_auth.password);
 		curl_easy_setopt(result, CURLOPT_USERPWD, up.buf);
 	}
-- 
1.8.3.1.440.gc2bf105

             reply	other threads:[~2013-06-18  2:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18  2:00 Brandon Casey [this message]
2013-06-18  4:15 ` [PATCH] http.c: don't rewrite the user:passwd string multiple times Eric Sunshine
2013-06-18  5:19 ` Jeff King
2013-06-18  6:36   ` Daniel Stenberg
2013-06-18 15:32     ` Junio C Hamano
2013-06-18 19:29   ` Brandon Casey
2013-06-18 22:13     ` Jeff King
2013-06-19  2:41       ` Brandon Casey
2013-06-19  2:43         ` [PATCH v2] " Brandon Casey
2013-06-19  5:26           ` Jeff King
2013-06-19  7:40       ` [PATCH] " Daniel Stenberg

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=1371520840-24906-1-git-send-email-bcasey@nvidia.com \
    --to=bcasey@nvidia.com \
    --cc=drafnel@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).