git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] http.c: don't rewrite the user:passwd string multiple times
@ 2013-06-18  2:00 Brandon Casey
  2013-06-18  4:15 ` Eric Sunshine
  2013-06-18  5:19 ` Jeff King
  0 siblings, 2 replies; 11+ messages in thread
From: Brandon Casey @ 2013-06-18  2:00 UTC (permalink / raw)
  To: git; +Cc: peff, gitster, Brandon Casey

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-06-19  7:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-18  2:00 [PATCH] http.c: don't rewrite the user:passwd string multiple times Brandon Casey
2013-06-18  4:15 ` 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

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).