Skip to content

Commit d8fab07

Browse files
rctaygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eb9d47c commit d8fab07

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

remote-curl.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "sideband.h"
1010

1111
static struct remote *remote;
12-
static const char *url;
12+
static const char *url; /* always ends with a trailing slash */
1313
static struct walker *walker;
1414

1515
struct options {
@@ -108,7 +108,7 @@ static struct discovery* discover_refs(const char *service)
108108
return last;
109109
free_discovery(last);
110110

111-
strbuf_addf(&buffer, "%s/info/refs", url);
111+
strbuf_addf(&buffer, "%sinfo/refs", url);
112112
if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
113113
is_http = 1;
114114
if (!strchr(url, '?'))
@@ -128,7 +128,7 @@ static struct discovery* discover_refs(const char *service)
128128
strbuf_reset(&buffer);
129129

130130
proto_git_candidate = 0;
131-
strbuf_addf(&buffer, "%s/info/refs", url);
131+
strbuf_addf(&buffer, "%sinfo/refs", url);
132132
refs_url = strbuf_detach(&buffer, NULL);
133133

134134
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)
518518
rpc->out = client.out;
519519
strbuf_init(&rpc->result, 0);
520520

521-
strbuf_addf(&buf, "%s/%s", url, svc);
521+
strbuf_addf(&buf, "%s%s", url, svc);
522522
rpc->service_url = strbuf_detach(&buf, NULL);
523523

524524
strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
@@ -805,11 +805,13 @@ int main(int argc, const char **argv)
805805
remote = remote_get(argv[1]);
806806

807807
if (argc > 2) {
808-
url = argv[2];
808+
end_url_with_slash(&buf, argv[2]);
809809
} else {
810-
url = remote->url[0];
810+
end_url_with_slash(&buf, remote->url[0]);
811811
}
812812

813+
url = strbuf_detach(&buf, NULL);
814+
813815
do {
814816
if (strbuf_getline(&buf, stdin, '\n') == EOF)
815817
break;

t/t5541-http-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cat >exp <<EOF
3838
GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
3939
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
4040
EOF
41-
test_expect_failure 'no empty path components' '
41+
test_expect_success 'no empty path components' '
4242
# In the URL, add a trailing slash, and see if git appends yet another
4343
# slash.
4444
cd "$ROOT_PATH" &&

0 commit comments

Comments
 (0)