Commit Diff


commit - b26177ada1d244a139f037595c3d8119c8fcdb14
commit + 26ec43f5492676f9f278c13bb5333f19ac5d7cba
blob - ad6558823eb4a56f19fd34da7ba498efdc206421
blob + 7f477b4bb76ad77d4a47b07bcb7dfc02471a82d5
--- lib/dial.c
+++ lib/dial.c
@@ -84,7 +84,6 @@ got_dial_parse_uri(char **proto, char **host, char **p
 {
 	const struct got_error *err = NULL;
 	char *s, *p, *q;
-	int n;
 
 	*proto = *host = *port = *server_path = *repo_name = NULL;
 
@@ -113,6 +112,10 @@ got_dial_parse_uri(char **proto, char **host, char **p
 			err = got_error_from_errno("strndup");
 			goto done;
 		}
+		if ((*host)[0] == '\0') {
+			err = got_error(GOT_ERR_PARSE_URI);
+			goto done;
+		}
 		p = q + 1;
 	} else {
 		*proto = strndup(uri, p - uri);
@@ -135,17 +138,29 @@ got_dial_parse_uri(char **proto, char **host, char **p
 				err = got_error_from_errno("strndup");
 				goto done;
 			}
+			if ((*host)[0] == '\0') {
+				err = got_error(GOT_ERR_PARSE_URI);
+				goto done;
+			}
 			*port = strndup(q + 1, p - (q + 1));
 			if (*port == NULL) {
 				err = got_error_from_errno("strndup");
 				goto done;
 			}
+			if ((*port)[0] == '\0') {
+				err = got_error(GOT_ERR_PARSE_URI);
+				goto done;
+			}
 		} else {
 			*host = strndup(s, p - s);
 			if (*host == NULL) {
 				err = got_error_from_errno("strndup");
 				goto done;
 			}
+			if ((*host)[0] == '\0') {
+				err = got_error(GOT_ERR_PARSE_URI);
+				goto done;
+			}
 		}
 	}
 
@@ -157,25 +172,18 @@ got_dial_parse_uri(char **proto, char **host, char **p
 		goto done;
 	}
 	got_path_strip_trailing_slashes(*server_path);
-
-	p = strrchr(p, '/');
-	if (!p || strlen(p) <= 1) {
+	if ((*server_path)[0] == '\0') {
 		err = got_error(GOT_ERR_PARSE_URI);
 		goto done;
 	}
-	p++;
-	n = strlen(p);
-	if (n == 0) {
-		err = got_error(GOT_ERR_PARSE_URI);
+
+	err = got_path_basename(repo_name, *server_path);
+	if (err)
 		goto done;
-	}
-	if (hassuffix(p, ".git"))
-		n -= 4;
-	*repo_name = strndup(p, (p + n) - p);
-	if (*repo_name == NULL) {
-		err = got_error_from_errno("strndup");
-		goto done;
-	}
+	if (hassuffix(*repo_name, ".git"))
+		(*repo_name)[strlen(*repo_name) - 4] = '\0';
+	if ((*repo_name)[0] == '\0')
+		err = got_error(GOT_ERR_PARSE_URI);
 done:
 	if (err) {
 		free(*proto);
blob - a9e4ce797d55e5000ac00da06faf04ba29ea2c18
blob + d4b990cae39ace16ca2ade92e3654f6d6466c606
--- regress/fetch/fetch_test.c
+++ regress/fetch/fetch_test.c
@@ -76,7 +76,7 @@ fetch_parse_uri(void)
 		{ "git://localhost////",
 		    NULL, NULL, NULL, NULL, NULL, GOT_ERR_PARSE_URI },
 		{ "git://127.0.0.1/git/",
-		    NULL, NULL, NULL, NULL, NULL, GOT_ERR_PARSE_URI },
+		    "git", "127.0.0.1", NULL, "/git", "git", GOT_ERR_OK },
 		{ "git:///127.0.0.1/git/",
 		    NULL, NULL, NULL, NULL, NULL, GOT_ERR_PARSE_URI },
 		{ "/127.0.0.1:/git/",