commit 84073f62fdfec793493251a7adbb339cd265a45b from: Mark Jamsek via: Thomas Adam date: Tue Feb 07 20:14:55 2023 UTC got: use intermediate pointers to plug leak on realloc And save worktree_branch_len for reuse. ok stsp@ and op@ commit - a6d87ea2fa484657855fbde3ed06fe6428d42a81 commit + 84073f62fdfec793493251a7adbb339cd265a45b blob - 833aa4774ec73e0cfd4481a27621ad0a4756b439 blob + fff73bb7371e7714cf0740195901c3c7c95c0ffb --- 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 - 214835009ac382bf53e72dc7f937838e4f30a027 blob + 6bb936e82376abc57ffcb9ed87cb250d34fc093b --- 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) {