Commit Diff


commit - 17e46db594a295989340e4610fa50e8c075e2254881566a724a42d5ebc8f4c21
commit + 4174659e52427b7735c85d6561739b4e4323ad3c5594f45d131e6399d9194c3a
blob - 1be166fb18e0fb01f0462abefaed0598f5ab52239d17cad14eebeaff5c9b61fa
blob + 54f207b5181f199711cd3a0bb28a51fd5178d7c3ce1e1332623ed705378ec155
--- lib/privsep.c	
+++ lib/privsep.c	
@@ -3326,19 +3326,16 @@ got_privsep_send_object_idlist_done(struct imsgbuf *ib
 	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;
@@ -3356,14 +3353,16 @@ got_privsep_recv_object_idlist(int *done, struct got_o
 			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;
@@ -3375,9 +3374,30 @@ got_privsep_recv_object_idlist(int *done, struct got_o
 
 	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	
@@ -1041,7 +1041,7 @@ recv_object_ids(struct got_object_idset *idset, struct
 	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;
@@ -1069,9 +1069,9 @@ recv_object_id_queue(size_t *nids_total, struct got_ob
 	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++) {