Skip to content

Commit f39f72d

Browse files
Gabriel Coronagitster
authored andcommitted
Fix username and password extraction from HTTP URLs
Change the authentification initialisation to percent-decode username and password for HTTP URLs. Signed-off-by: Gabriel Corona <[email protected]> Acked-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3cf8fe1 commit f39f72d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

http.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "pack.h"
33
#include "sideband.h"
44
#include "run-command.h"
5+
#include "url.h"
56

67
int data_received;
78
int active_requests;
@@ -297,7 +298,7 @@ static CURL *get_curl_handle(void)
297298

298299
static void http_auth_init(const char *url)
299300
{
300-
char *at, *colon, *cp, *slash;
301+
char *at, *colon, *cp, *slash, *decoded;
301302
int len;
302303

303304
cp = strstr(url, "://");
@@ -322,16 +323,25 @@ static void http_auth_init(const char *url)
322323
user_name = xmalloc(len + 1);
323324
memcpy(user_name, cp, len);
324325
user_name[len] = '\0';
326+
decoded = url_decode(user_name);
327+
free(user_name);
328+
user_name = decoded;
325329
user_pass = NULL;
326330
} else {
327331
len = colon - cp;
328332
user_name = xmalloc(len + 1);
329333
memcpy(user_name, cp, len);
330334
user_name[len] = '\0';
335+
decoded = url_decode(user_name);
336+
free(user_name);
337+
user_name = decoded;
331338
len = at - (colon + 1);
332339
user_pass = xmalloc(len + 1);
333340
memcpy(user_pass, colon + 1, len);
334341
user_pass[len] = '\0';
342+
decoded = url_decode(user_pass);
343+
free(user_pass);
344+
user_pass = decoded;
335345
}
336346
}
337347

t/t5550-http-fetch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test_expect_success 'clone http repository' '
3434
test_cmp file clone/file
3535
'
3636

37-
test_expect_failure 'clone http repository with authentication' '
37+
test_expect_success 'clone http repository with authentication' '
3838
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
3939
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
4040
git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&

0 commit comments

Comments
 (0)