@matheusbsbs / matheus-bagliano / commits / d8fab07208
Fork 0

remote-curl: ensure that URLs have a trailing slash

Previously, we blindly assumed that URLs passed to the remote-curl helper did not end with a trailing slash. Use the convenience function end_url_with_slash() from http.[ch] to ensure that URLs have a trailing slash on invocation of the remote-curl helper, and use the URL as one with a trailing slash throughout. It is possible for users to pass a URL with a trailing slash to remote-curl, by, say, setting it in remote.<name>.url in their git config. The resulting requests have an empty path component (//) and may break implementations of the http git protocol. Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Apr 8, 2010 at 10:15 UTC d8fab07208abfbe7dc93aea97c5577cdd73266c5
2 files changed +9 -7
remote-curl.c
+8 -6
@@ -9,7 +9,7 @@
9 #include "sideband.h"
10
11 static struct remote *remote;
12 -static const char *url;
12 +static const char *url; /* always ends with a trailing slash */
13 static struct walker *walker;
14
15 struct options {
@@ -108,7 +108,7 @@ static struct discovery* discover_refs(const char *service)
108 return last;
109 free_discovery(last);
110
111 - strbuf_addf(&buffer, "%s/info/refs", url);
111 + strbuf_addf(&buffer, "%sinfo/refs", url);
112 if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
113 is_http = 1;
114 if (!strchr(url, '?'))
@@ -128,7 +128,7 @@ static struct discovery* discover_refs(const char *service)
128 strbuf_reset(&buffer);
129
130 proto_git_candidate = 0;
131 - strbuf_addf(&buffer, "%s/info/refs", url);
131 + strbuf_addf(&buffer, "%sinfo/refs", url);
132 refs_url = strbuf_detach(&buffer, NULL);
133
134 http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
@@ -518,7 +518,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
518 rpc->out = client.out;
519 strbuf_init(&rpc->result, 0);
520
521 - strbuf_addf(&buf, "%s/%s", url, svc);
521 + strbuf_addf(&buf, "%s%s", url, svc);
522 rpc->service_url = strbuf_detach(&buf, NULL);
523
524 strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
@@ -805,11 +805,13 @@ int main(int argc, const char **argv)
805 remote = remote_get(argv[1]);
806
807 if (argc > 2) {
808 - url = argv[2];
808 + end_url_with_slash(&buf, argv[2]);
809 } else {
810 - url = remote->url[0];
810 + end_url_with_slash(&buf, remote->url[0]);
811 }
812
813 + url = strbuf_detach(&buf, NULL);
814 +
815 do {
816 if (strbuf_getline(&buf, stdin, '\n') == EOF)
817 break;
t/t5541-http-push.sh
+1 -1
@@ -38,7 +38,7 @@ cat >exp <<EOF
38 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
39 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
40 EOF
41 -test_expect_failure 'no empty path components' '
41 +test_expect_success 'no empty path components' '
42 # In the URL, add a trailing slash, and see if git appends yet another
43 # slash.
44 cd "$ROOT_PATH" &&