commit - 17e46db594a295989340e4610fa50e8c075e2254881566a724a42d5ebc8f4c21
commit + 4174659e52427b7735c85d6561739b4e4323ad3c5594f45d131e6399d9194c3a
blob - 1be166fb18e0fb01f0462abefaed0598f5ab52239d17cad14eebeaff5c9b61fa
blob + 54f207b5181f199711cd3a0bb28a51fd5178d7c3ce1e1332623ed705378ec155
--- lib/privsep.c
+++ lib/privsep.c
return flush_imsg(ibuf);
}
-const struct got_error *
-got_privsep_recv_object_idlist(int *done, struct got_object_id **ids,
+static const struct got_error *
+recv_object_idlist_chunk(int *done, struct got_object_id **ids,
size_t *nids, struct imsgbuf *ibuf)
{
const struct got_error *err = NULL;
struct imsg imsg;
struct got_imsg_object_idlist *idlist;
+ struct got_object_id *new = NULL;
size_t datalen;
- *ids = NULL;
- *done = 0;
- *nids = 0;
-
err = got_privsep_recv_imsg(&imsg, ibuf, 0);
if (err)
return err;
err = got_error(GOT_ERR_PRIVSEP_LEN);
break;
}
- *nids = idlist->nids;
- *ids = calloc(*nids, sizeof(**ids));
- if (*ids == NULL) {
- err = got_error_from_errno("calloc");
+ new = recallocarray(*ids, *nids, *nids + idlist->nids,
+ sizeof(**ids));
+ if (new == NULL) {
+ err = got_error_from_errno("recallocarray");
break;
}
- memcpy(*ids, (uint8_t *)imsg.data + sizeof(*idlist),
- *nids * sizeof(**ids));
+ *ids = new;
+ memcpy(*ids + *nids, (uint8_t *)imsg.data + sizeof(*idlist),
+ idlist->nids * sizeof(**ids));
+ *nids += idlist->nids;
break;
case GOT_IMSG_OBJ_ID_LIST_DONE:
*done = 1;
imsg_free(&imsg);
+ if (err) {
+ free(*ids);
+ *ids = NULL;
+ *nids = 0;
+ }
return err;
}
+const struct got_error *
+got_privsep_recv_object_idlist(int *done, struct got_object_id **ids,
+ size_t *nids, struct imsgbuf *ibuf)
+{
+ const struct got_error *err = NULL;
+
+ *ids = NULL;
+ *done = 0;
+ *nids = 0;
+
+ while (err == NULL && *done == 0)
+ err = recv_object_idlist_chunk(done, ids, nids, ibuf);
+
+ return err;
+}
+
static const struct got_error *
send_qidlist(struct imsgbuf *ibuf, struct got_object_qid **qids, size_t nids)
{
blob - 9b649722260c35accfcb4b5de56c426f821490a5e33fcf1ae6f6ece62e30dce5
blob + 6feb8535ed41cb3b56d0d4d40499de7110259aef287f266d6a343ae96e46b136
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
struct got_object_id *ids;
size_t nids, i;
- for (;;) {
+ while (!done) {
err = got_privsep_recv_object_idlist(&done, &ids, &nids, ibuf);
if (err || done)
break;
size_t nids, i;
*nids_total = 0;
- for (;;) {
+ while (!done) {
err = got_privsep_recv_object_idlist(&done, &ids, &nids, ibuf);
- if (err || done)
+ if (err)
break;
*nids_total += nids;
for (i = 0; i < nids; i++) {