summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-11-01 04:22:12 -0700
committerVicent Martí <vicent@github.com>2013-11-01 04:22:12 -0700
commitab44c62e548373c1494e967f54720faa06ce38b7 (patch)
treecd9dd4e90f790a99534f8024f8686a8d8672f117 /src
parentf93f3790c511d3ed821bf63fdaf5aeec155e195b (diff)
parent048f837b2fd5cd12ed7e3ca497f11460ab3114a9 (diff)
downloadlibgit2-ab44c62e548373c1494e967f54720faa06ce38b7.tar.gz
Merge pull request #1928 from libgit2/parse-bad-urls
Improve bad URL handling
Diffstat (limited to 'src')
-rw-r--r--src/netops.c7
-rw-r--r--src/transports/ssh.c11
2 files changed, 10 insertions, 8 deletions
diff --git a/src/netops.c b/src/netops.c
index 7a61ef820..7e13f12e7 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -679,9 +679,10 @@ int gitno_extract_url_parts(
slash = strchr(url, '/');
at = strchr(url, '@');
- if (slash == NULL) {
- giterr_set(GITERR_NET, "Malformed URL: missing /");
- return -1;
+ if (!slash ||
+ (colon && (slash < colon))) {
+ giterr_set(GITERR_NET, "Malformed URL");
+ return GIT_EINVALIDSPEC;
}
start = url;
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 6ce673d5e..4e2834b49 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -213,10 +213,6 @@ static int git_ssh_extract_url_parts(
colon = strchr(url, ':');
- if (colon == NULL) {
- giterr_set(GITERR_NET, "Malformed URL: missing :");
- return -1;
- }
at = strchr(url, '@');
if (at) {
@@ -228,6 +224,11 @@ static int git_ssh_extract_url_parts(
*username = NULL;
}
+ if (colon == NULL || (colon < start)) {
+ giterr_set(GITERR_NET, "Malformed URL");
+ return -1;
+ }
+
*host = git__substrdup(start, colon - start);
GITERR_CHECK_ALLOC(*host);
@@ -316,7 +317,7 @@ static int _git_ssh_setup_conn(
const char *cmd,
git_smart_subtransport_stream **stream)
{
- char *host, *port=NULL, *user=NULL, *pass=NULL;
+ char *host=NULL, *port=NULL, *user=NULL, *pass=NULL;
const char *default_port="22";
ssh_stream *s;
LIBSSH2_SESSION* session=NULL;