Commit Diff


commit - ba4dfaf77ed2c311eaabc0b99e96083ba548c937
commit + ec218e165dfd906f44ad491671127ca4b6979ed0
blob - d99805a6e345d6d142e6a571b2f787068b19ef76
blob + 8954b4c42e443bbd5ba01b707de2fd26e6410d19
--- lib/privsep.c
+++ lib/privsep.c
@@ -536,13 +536,14 @@ got_privsep_send_fetch_req(struct imsgbuf *ibuf, int f
 {
 	const struct got_error *err = NULL;
 	struct ibuf *wbuf;
-	size_t len;
+	size_t len, worktree_branch_len;
 	struct got_pathlist_entry *pe;
 	struct got_imsg_fetch_request fetchreq;
 
-	if (worktree_branch)
-		len = sizeof(fetchreq) + strlen(worktree_branch);
-	else
+	if (worktree_branch) {
+		worktree_branch_len = strlen(worktree_branch);
+		len = sizeof(fetchreq) + worktree_branch_len;
+	} else
 		len = sizeof(fetchreq);
 
 	if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
@@ -559,7 +560,7 @@ got_privsep_send_fetch_req(struct imsgbuf *ibuf, int f
 	fetchreq.list_refs_only = list_refs_only;
 	fetchreq.verbosity = verbosity;
 	if (worktree_branch != NULL)
-		fetchreq.worktree_branch_len = strlen(worktree_branch);
+		fetchreq.worktree_branch_len = worktree_branch_len;
 	TAILQ_FOREACH(pe, have_refs, entry)
 		fetchreq.n_have_refs++;
 	TAILQ_FOREACH(pe, wanted_branches, entry)
@@ -569,8 +570,7 @@ got_privsep_send_fetch_req(struct imsgbuf *ibuf, int f
 	if (imsg_add(wbuf, &fetchreq, sizeof(fetchreq)) == -1)
 		return got_error_from_errno("imsg_add FETCH_REQUEST");
 	if (worktree_branch) {
-		if (imsg_add(wbuf, worktree_branch,
-		    strlen(worktree_branch))== -1)
+		if (imsg_add(wbuf, worktree_branch, worktree_branch_len) == -1)
 			return got_error_from_errno("imsg_add FETCH_REQUEST");
 	}
 	wbuf->fd = fd;
blob - 32778499296b895c8f8a0bd7f201ca9a637c6f87
blob + f21581a8de91fa478a72e20f422c81a342ce59e8
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
@@ -385,17 +385,21 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
 			goto done;
 
 		if (refsz == nref + 1) {
+			struct got_object_id *h, *w;
+
 			refsz *= 2;
-			have = reallocarray(have, refsz, sizeof(have[0]));
-			if (have == NULL) {
+			h = reallocarray(have, refsz, sizeof(have[0]));
+			if (h == NULL) {
 				err = got_error_from_errno("reallocarray");
 				goto done;
 			}
-			want = reallocarray(want, refsz, sizeof(want[0]));
-			if (want == NULL) {
+			have = h;
+			w = reallocarray(want, refsz, sizeof(want[0]));
+			if (w == NULL) {
 				err = got_error_from_errno("reallocarray");
 				goto done;
 			}
+			want = w;
 		}
 
 		if (is_firstpkt) {