Commit Diff


commit - 76911fd28aa2313e62eb8f866862047c4befc10d
commit + 406106eeba86b56f002743d48661fd5bac312e31
blob - ff77adba05310befc369700544a6520a6ce0dc1b
blob + ece8d970d5f05387089cfe02e0c2d2f26479821f
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
@@ -320,9 +320,8 @@ match_capability(char **my_capabilities, const char *c
 			return NULL;
 	}
 
-	if (asprintf(&s, "%s%s%s%s%s",
+	if (asprintf(&s, "%s %s%s%s",
 	    *my_capabilities != NULL ? *my_capabilities : "",
-	    *my_capabilities != NULL ? " " : "",
 	    mycapa->key,
 	    mycapa->value != NULL ? "=" : "",
 	    mycapa->value != NULL? mycapa->value : "") == -1)
@@ -399,6 +398,11 @@ match_capabilities(char **my_capabilities, struct got_
 		}
 	} while (capa);
 
+	if (*my_capabilities == NULL) {
+		*my_capabilities = strdup("");
+		if (*my_capabilities == NULL)
+			err = got_error_from_errno("strdup");
+	}
 	return err;
 }
 
@@ -460,7 +464,7 @@ fetch_pack(int fd, int packfd, struct got_object_id *p
 	char *server_capabilities = NULL, *my_capabilities = NULL;
 	struct got_pathlist_head symrefs;
 	struct got_pathlist_entry *pe;
-	int have_sidebands = 0;
+	int sent_my_capabilites = 0, have_sidebands = 0;
 
 	TAILQ_INIT(&symrefs);
 
@@ -530,9 +534,8 @@ fetch_pack(int fd, int packfd, struct got_object_id *p
 		if (got_object_id_cmp(&have[i], &want[i]) == 0)
 			continue;
 		got_sha1_digest_to_str(want[i].sha1, hashstr, sizeof(hashstr));
-		n = snprintf(buf, sizeof(buf), "want %s%s%s\n", hashstr,
-		   i == 0 && my_capabilities ? " " : "",
-		   i == 0 && my_capabilities ? my_capabilities : "");
+		n = snprintf(buf, sizeof(buf), "want %s%s\n", hashstr,
+		   sent_my_capabilites ? "" : my_capabilities);
 		if (n >= sizeof(buf)) {
 			err = got_error(GOT_ERR_NO_SPACE);
 			goto done;