Skip to content

http: avoid generating double slashes in url#5325

Merged
pks-t merged 1 commit intolibgit2:masterfrom
josharian:no-double-slash
Jan 6, 2020
Merged

http: avoid generating double slashes in url#5325
pks-t merged 1 commit intolibgit2:masterfrom
josharian:no-double-slash

Conversation

@josharian
Copy link
Contributor

@josharian josharian commented Dec 6, 2019

Prior to this change, given a remote url with a trailing slash,
such as http://localhost/a/, service requests would contain a
double slash: http://localhost/a//info/refs?service=git-receive-pack.
Prevent that.

I was unable to test the winhttp.c changes locally. I trust that CI will cover that.

Updates #5321

cc @ethomson

Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes a lot of sense, so I'm 👍

size_t pathlen = strlen(path);
/* If path already ends in /, remove the leading slash from service_url */
if (pathlen > 0 && path[pathlen - 1] == '/')
service_url++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (git__suffixcmp(path, "/"))
    service_url++;

We could also check if service_url actually starts with a "/" as kind of a sanity check even though currently this is always the case.

if (git__suffixcmp(path, "/") && git__prefixcmp(s->service_url, "/"))
    service_url++;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

@josharian
Copy link
Contributor Author

I can't tell why the CI failed. It appears it may have to do with fuzzing leaking a fd, which I think is unlikely to be caused by this PR, but I'm not sure.

josharian added a commit to josharian/libgit2 that referenced this pull request Dec 13, 2019
Some servers leave the query parameters intact in the
Location header when responding with a redirect.
The service_suffix removal check as written assumed
that the server removed them.
Handle both cases.

Along with PR libgit2#5325, this fixes libgit2#5321.
Prior to this change, given a remote url with a trailing slash,
such as http://localhost/a/, service requests would contain a
double slash: http://localhost/a//info/refs?service=git-receive-pack.
Detect and prevent that.

Updates libgit2#5321
@josharian
Copy link
Contributor Author

Looks like the CI failure was a flake; I re-ran with the same code and it passed.

@ethomson
Copy link
Member

Yep, we have tests that actually hit the network and are thus a bit flaky. Apologies for the inconvenience.

Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks a lot for this fix!

@pks-t pks-t merged commit 33f93bf into libgit2:master Jan 6, 2020
josharian added a commit to josharian/git2go that referenced this pull request Jan 8, 2020
to pick up libgit2/libgit2#5325

Merge commit '69df156d02d5733bcb981960fde9b4d8e185ff73' into v28
josharian added a commit to josharian/libgit2 that referenced this pull request Jan 9, 2020
Some servers leave the query parameters intact in the
Location header when responding with a redirect.
The service_suffix removal check as written assumed
that the server removed them.
Handle both cases.

Along with PR libgit2#5325, this fixes libgit2#5321.

There are two new tests. The first already passed;
the second previously failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants