From: Johannes Schindelin <johannes.schindelin@xxxxxx> Prior to the fixes for CVE-2020-11008, we were _very_ lenient in what we required from a URL in order to parse it into a `struct credential`. That led to serious vulnerabilities. There was one call site, though, that really needed that leniency: when parsing config settings a la `credential.dev.azure.com.useHTTPPath`. In preparation for fixing that regression, let's add a parameter called `strict` to the `credential_from_url()` function and convert the existing callers to enforce that strict mode. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- credential.c | 14 ++++++++------ credential.h | 6 +++++- fsck.c | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/credential.c b/credential.c index 64a841eddca..c73260ac40f 100644 --- a/credential.c +++ b/credential.c @@ -344,7 +344,7 @@ static int check_url_component(const char *url, int quiet, } int credential_from_url_gently(struct credential *c, const char *url, - int quiet) + int strict, int quiet) { const char *at, *colon, *cp, *slash, *host, *proto_end; @@ -357,12 +357,12 @@ int credential_from_url_gently(struct credential *c, const char *url, * (3) proto://<user>:<pass>@<host>/... */ proto_end = strstr(url, "://"); - if (!proto_end || proto_end == url) { + if (strict && (!proto_end || proto_end == url)) { if (!quiet) warning(_("url has no scheme: %s"), url); return -1; } - cp = proto_end + 3; + cp = proto_end ? proto_end + 3 : url; at = strchr(cp, '@'); colon = strchr(cp, ':'); slash = strchrnul(cp, '/'); @@ -382,8 +382,10 @@ int credential_from_url_gently(struct credential *c, const char *url, host = at + 1; } - c->protocol = xmemdupz(url, proto_end - url); - c->host = url_decode_mem(host, slash - host); + if (proto_end && proto_end - url > 0) + c->protocol = xmemdupz(url, proto_end - url); + if (slash - url > 0) + c->host = url_decode_mem(host, slash - host); /* Trim leading and trailing slashes from path */ while (*slash == '/') slash++; @@ -407,6 +409,6 @@ int credential_from_url_gently(struct credential *c, const char *url, void credential_from_url(struct credential *c, const char *url) { - if (credential_from_url_gently(c, url, 0) < 0) + if (credential_from_url_gently(c, url, 1, 0) < 0) die(_("credential url cannot be parsed: %s"), url); } diff --git a/credential.h b/credential.h index 5a86502d95c..823ec2caf35 100644 --- a/credential.h +++ b/credential.h @@ -41,9 +41,13 @@ void credential_write(const struct credential *, FILE *); * an error but leave the broken state in the credential object for further * examination. The non-gentle form will issue a warning to stderr and return * an empty credential. + * + * In strict mode, an empty protocol or an empty host name are not allowed. + * The credential_from_url() function enforces strict mode. */ void credential_from_url(struct credential *, const char *url); -int credential_from_url_gently(struct credential *, const char *url, int quiet); +int credential_from_url_gently(struct credential *, const char *url, + int strict, int quiet); int credential_match(const struct credential *have, const struct credential *want); diff --git a/fsck.c b/fsck.c index 31b5be05f54..aa66dc1e742 100644 --- a/fsck.c +++ b/fsck.c @@ -1076,7 +1076,7 @@ static int check_submodule_url(const char *url) else if (url_to_curl_url(url, &curl_url)) { struct credential c = CREDENTIAL_INIT; int ret = 0; - if (credential_from_url_gently(&c, curl_url, 1) || + if (credential_from_url_gently(&c, curl_url, 1, 1) || !*c.host) ret = -1; credential_clear(&c); -- gitgitgadget