summaryrefslogtreecommitdiff
path: root/credential.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-03-25 20:07:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-03-25 20:07:47 (GMT)
commitde49261b050d9cd8ec73842356077bc5b606640f (patch)
treeaff75b1af189d2c3d2dffe6d5d3ba6f2f812ce08 /credential.c
parent274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925 (diff)
parent67b0a24910fbb23c8f5e7a2c61c339818bc68296 (diff)
downloadgit-de49261b050d9cd8ec73842356077bc5b606640f.zip
git-de49261b050d9cd8ec73842356077bc5b606640f.tar.gz
git-de49261b050d9cd8ec73842356077bc5b606640f.tar.bz2
Git 2.26.1v2.26.1
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'credential.c')
-rw-r--r--credential.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/credential.c b/credential.c
index 77dfde4..21b3ba1 100644
--- a/credential.c
+++ b/credential.c
@@ -226,6 +226,8 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)
{
if (!value)
return;
+ if (strchr(value, '\n'))
+ die("credential value for %s contains newline", key);
fprintf(fp, "%s=%s\n", key, value);
}
@@ -353,7 +355,22 @@ void credential_reject(struct credential *c)
c->approved = 0;
}
-void credential_from_url(struct credential *c, const char *url)
+static int check_url_component(const char *url, int quiet,
+ const char *name, const char *value)
+{
+ if (!value)
+ return 0;
+ if (!strchr(value, '\n'))
+ return 0;
+
+ if (!quiet)
+ warning(_("url contains a newline in its %s component: %s"),
+ name, url);
+ return -1;
+}
+
+int credential_from_url_gently(struct credential *c, const char *url,
+ int quiet)
{
const char *at, *colon, *cp, *slash, *host, *proto_end;
@@ -367,7 +384,7 @@ void credential_from_url(struct credential *c, const char *url)
*/
proto_end = strstr(url, "://");
if (!proto_end)
- return;
+ return 0;
cp = proto_end + 3;
at = strchr(cp, '@');
colon = strchr(cp, ':');
@@ -406,4 +423,21 @@ void credential_from_url(struct credential *c, const char *url)
while (p > c->path && *p == '/')
*p-- = '\0';
}
+
+ if (check_url_component(url, quiet, "username", c->username) < 0 ||
+ check_url_component(url, quiet, "password", c->password) < 0 ||
+ check_url_component(url, quiet, "protocol", c->protocol) < 0 ||
+ check_url_component(url, quiet, "host", c->host) < 0 ||
+ check_url_component(url, quiet, "path", c->path) < 0)
+ return -1;
+
+ return 0;
+}
+
+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);
+ }
}