Commit Diff


commit - 9b45e112d9c37d7cae9eeb9c108cbf655f39e411
commit + 4312a4983212b89db48350c7eef88a3f1c027d85
blob - b4b32476a836036ce708103689ae0997933c403d
blob + 83435ade8c0f36340678bfe485c738fc0cbe8fb8
--- lib/fetch.c
+++ lib/fetch.c
@@ -178,7 +178,7 @@ dial_git(int *fetchfd, char *host, char *port, char *p
 	const struct got_error *err = NULL;
 	struct addrinfo hints, *servinfo, *p;
 	char *cmd = NULL, *pkt = NULL;
-	int fd = -1, l, r, eaicode;
+	int fd = -1, totlen, r, eaicode;
 
 	*fetchfd = -1;
 
@@ -201,17 +201,29 @@ dial_git(int *fetchfd, char *host, char *port, char *p
 	if (p == NULL)
 		goto done;
 
-	if ((l = asprintf(&cmd, "git-%s-pack %s\n", direction, path)) == -1) {
+	if (asprintf(&cmd, "git-%s-pack %s", direction, path) == -1) {
 		err = got_error_from_errno("asprintf");
 		goto done;
 	}
-	if ((l = asprintf(&pkt, "%04x%s", l + 4, cmd)) == -1) {
+	totlen = 4 + strlen(cmd) + 1 + strlen("host=") + strlen(host) + 1;
+	if (asprintf(&pkt, "%04x%s", totlen, cmd) == -1) {
 		err = got_error_from_errno("asprintf");
 		goto done;
 	}
-	r = write(fd, pkt, l);
-	if (r == -1)
+	r = write(fd, pkt, strlen(pkt) + 1);
+	if (r == -1) {
+		err = got_error_from_errno("write");
+		goto done;
+	}
+	if (asprintf(&pkt, "host=%s", host) == -1) {
+		err = got_error_from_errno("asprintf");
+		goto done;
+	}
+	r = write(fd, pkt, strlen(pkt) + 1);
+	if (r == -1) {
 		err = got_error_from_errno("write");
+		goto done;
+	}
 done:
 	free(cmd);
 	free(pkt);