From 9ee6bcd398057cb0cf3c52b9dc93b094d3d37235 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 8 Apr 2010 10:15:16 +0800 Subject: [PATCH 1/3] t5541-http-push: add test for URLs with trailing slash Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- t/t5541-http-push.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index 53f54a2789..7873d9429a 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -34,8 +34,34 @@ test_expect_success 'setup remote repository' ' mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" ' -test_expect_success 'clone remote repository' ' +cat >exp <act <"$HTTPD_ROOT_PATH"/access.log && + + # Clear the log, so that it does not affect the "used receive-pack + # service" test which reads the log too. + # + # We do this before the actual comparison to ensure the log is cleared. + echo > "$HTTPD_ROOT_PATH"/access.log && + + test_cmp exp act +' + +test_expect_success 'clone remote repository' ' + rm -rf test_repo_clone && git clone $HTTPD_URL/smart/test_repo.git test_repo_clone ' @@ -68,6 +94,7 @@ test_expect_success 'create and delete remote branch' ' ' cat >exp < Date: Thu, 8 Apr 2010 10:15:17 +0800 Subject: [PATCH 2/3] http: make end_url_with_slash() public Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- http.c | 2 +- http.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/http.c b/http.c index deab59551d..163c0e48e4 100644 --- a/http.c +++ b/http.c @@ -720,7 +720,7 @@ static inline int hex(int v) return 'A' + v - 10; } -static void end_url_with_slash(struct strbuf *buf, const char *url) +void end_url_with_slash(struct strbuf *buf, const char *url) { strbuf_addstr(buf, url); if (buf->len && buf->buf[buf->len - 1] != '/') diff --git a/http.h b/http.h index 5c9441c10c..c78cacb9c3 100644 --- a/http.h +++ b/http.h @@ -117,6 +117,7 @@ extern void append_remote_object_url(struct strbuf *buf, const char *url, int only_two_digit_prefix); extern char *get_remote_object_url(const char *url, const char *hex, int only_two_digit_prefix); +extern void end_url_with_slash(struct strbuf *buf, const char *url); /* Options for http_request_*() */ #define HTTP_NO_CACHE 1 From d8fab07208abfbe7dc93aea97c5577cdd73266c5 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 8 Apr 2010 10:15:18 +0800 Subject: [PATCH 3/3] 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..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 Signed-off-by: Junio C Hamano --- remote-curl.c | 14 ++++++++------ t/t5541-http-push.sh | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/remote-curl.c b/remote-curl.c index a904164e42..1fe59d6db0 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -9,7 +9,7 @@ #include "sideband.h" static struct remote *remote; -static const char *url; +static const char *url; /* always ends with a trailing slash */ static struct walker *walker; struct options { @@ -108,7 +108,7 @@ static struct discovery* discover_refs(const char *service) return last; free_discovery(last); - strbuf_addf(&buffer, "%s/info/refs", url); + strbuf_addf(&buffer, "%sinfo/refs", url); if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) { is_http = 1; if (!strchr(url, '?')) @@ -128,7 +128,7 @@ static struct discovery* discover_refs(const char *service) strbuf_reset(&buffer); proto_git_candidate = 0; - strbuf_addf(&buffer, "%s/info/refs", url); + strbuf_addf(&buffer, "%sinfo/refs", url); refs_url = strbuf_detach(&buffer, NULL); 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) rpc->out = client.out; strbuf_init(&rpc->result, 0); - strbuf_addf(&buf, "%s/%s", url, svc); + strbuf_addf(&buf, "%s%s", url, svc); rpc->service_url = strbuf_detach(&buf, NULL); strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc); @@ -805,11 +805,13 @@ int main(int argc, const char **argv) remote = remote_get(argv[1]); if (argc > 2) { - url = argv[2]; + end_url_with_slash(&buf, argv[2]); } else { - url = remote->url[0]; + end_url_with_slash(&buf, remote->url[0]); } + url = strbuf_detach(&buf, NULL); + do { if (strbuf_getline(&buf, stdin, '\n') == EOF) break; diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index 7873d9429a..f0c50d3d77 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -38,7 +38,7 @@ cat >exp <