Skip to content

Commit

Permalink
Fix username and password extraction from HTTP URLs
Browse files Browse the repository at this point in the history
Change the authentification initialisation to percent-decode username
and password for HTTP URLs.

Signed-off-by: Gabriel Corona <gabriel.corona@enst-bretagne.fr>
Acked-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Gabriel Corona authored and Junio C Hamano committed Nov 17, 2010
1 parent 3cf8fe1 commit f39f72d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion http.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "pack.h"
#include "sideband.h"
#include "run-command.h"
#include "url.h"

int data_received;
int active_requests;
Expand Down Expand Up @@ -297,7 +298,7 @@ static CURL *get_curl_handle(void)

static void http_auth_init(const char *url)
{
char *at, *colon, *cp, *slash;
char *at, *colon, *cp, *slash, *decoded;
int len;

cp = strstr(url, "://");
Expand All @@ -322,16 +323,25 @@ static void http_auth_init(const char *url)
user_name = xmalloc(len + 1);
memcpy(user_name, cp, len);
user_name[len] = '\0';
decoded = url_decode(user_name);
free(user_name);
user_name = decoded;
user_pass = NULL;
} else {
len = colon - cp;
user_name = xmalloc(len + 1);
memcpy(user_name, cp, len);
user_name[len] = '\0';
decoded = url_decode(user_name);
free(user_name);
user_name = decoded;
len = at - (colon + 1);
user_pass = xmalloc(len + 1);
memcpy(user_pass, colon + 1, len);
user_pass[len] = '\0';
decoded = url_decode(user_pass);
free(user_pass);
user_pass = decoded;
}
}

Expand Down
2 changes: 1 addition & 1 deletion t/t5550-http-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test_expect_success 'clone http repository' '
test_cmp file clone/file
'

test_expect_failure 'clone http repository with authentication' '
test_expect_success 'clone http repository with authentication' '
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&
Expand Down

0 comments on commit f39f72d

Please sign in to comment.