Skip to content

Commit

Permalink
Merge branch 'jn/credential-url-blank'
Browse files Browse the repository at this point in the history
This backports the fix for CVE-2020-11008.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Apr 20, 2020
2 parents 5fbb082 + d4484ce commit f2ecda5
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 35 deletions.
39 changes: 23 additions & 16 deletions credential.c
Expand Up @@ -88,6 +88,11 @@ static int proto_is_http(const char *s)

static void credential_apply_config(struct credential *c)
{
if (!c->host)
die(_("refusing to work with credential missing host field"));
if (!c->protocol)
die(_("refusing to work with credential missing protocol field"));

if (c->configured)
return;
git_config(credential_config_callback, c);
Expand Down Expand Up @@ -192,8 +197,11 @@ int credential_read(struct credential *c, FILE *fp)
return 0;
}

static void credential_write_item(FILE *fp, const char *key, const char *value)
static void credential_write_item(FILE *fp, const char *key, const char *value,
int required)
{
if (!value && required)
BUG("credential value for %s is missing", key);
if (!value)
return;
if (strchr(value, '\n'))
Expand All @@ -203,11 +211,11 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)

void credential_write(const struct credential *c, FILE *fp)
{
credential_write_item(fp, "protocol", c->protocol);
credential_write_item(fp, "host", c->host);
credential_write_item(fp, "path", c->path);
credential_write_item(fp, "username", c->username);
credential_write_item(fp, "password", c->password);
credential_write_item(fp, "protocol", c->protocol, 1);
credential_write_item(fp, "host", c->host, 1);
credential_write_item(fp, "path", c->path, 0);
credential_write_item(fp, "username", c->username, 0);
credential_write_item(fp, "password", c->password, 0);
}

static int run_credential_helper(struct credential *c,
Expand Down Expand Up @@ -351,8 +359,11 @@ int credential_from_url_gently(struct credential *c, const char *url,
* (3) proto://<user>:<pass>@<host>/...
*/
proto_end = strstr(url, "://");
if (!proto_end)
return 0;
if (!proto_end || proto_end == url) {
if (!quiet)
warning(_("url has no scheme: %s"), url);
return -1;
}
cp = proto_end + 3;
at = strchr(cp, '@');
colon = strchr(cp, ':');
Expand All @@ -373,10 +384,8 @@ int credential_from_url_gently(struct credential *c, const char *url,
host = at + 1;
}

if (proto_end - url > 0)
c->protocol = xmemdupz(url, proto_end - url);
if (slash - host > 0)
c->host = url_decode_mem(host, slash - host);
c->protocol = xmemdupz(url, proto_end - url);
c->host = url_decode_mem(host, slash - host);
/* Trim leading and trailing slashes from path */
while (*slash == '/')
slash++;
Expand All @@ -400,8 +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) {
warning(_("skipping credential lookup for url: %s"), url);
credential_clear(c);
}
if (credential_from_url_gently(c, url, 0) < 0)
die(_("credential url cannot be parsed: %s"), url);
}
1 change: 1 addition & 0 deletions fsck.c
Expand Up @@ -7,6 +7,7 @@
#include "tag.h"
#include "fsck.h"
#include "refs.h"
#include "url.h"
#include "utf8.h"
#include "sha1-array.h"
#include "decorate.h"
Expand Down
1 change: 1 addition & 0 deletions http.c
Expand Up @@ -537,6 +537,7 @@ static int has_cert_password(void)
return 0;
if (!cert_auth.password) {
cert_auth.protocol = xstrdup("cert");
cert_auth.host = xstrdup("");
cert_auth.username = xstrdup("");
cert_auth.path = xstrdup(ssl_cert);
credential_fill(&cert_auth);
Expand Down

0 comments on commit f2ecda5

Please sign in to comment.