Commit Diff


commit - 1df44de6f73549388bc170ad065645811ab002d0
commit + 80985c16b7649d82b559b180b486ac017c864e5a
blob - ee575dbf080d9b5e9f2a1019a20d281907f06c91
blob + 1b9cd072c5f6b42f27f9626ef92aa04fa7c9b34c
--- lib/privsep.c
+++ lib/privsep.c
@@ -1592,36 +1592,13 @@ got_privsep_recv_tree(struct got_tree_object **tree, s
 
 	*tree = NULL;
 
-	err = read_imsg(ibuf);
-	if (err)
-		goto done;
-
-	for (;;) {
+	while (*tree == NULL || nentries < (*tree)->nentries) {
 		struct imsg imsg;
-		size_t n;
 		size_t datalen;
 
-		n = imsg_get(ibuf, &imsg);
-		if (n == 0) {
-			if ((*tree)) {
-				if (nentries < (*tree)->nentries) {
-					err = read_imsg(ibuf);
-					if (err)
-						break;
-					continue;
-				} else
-					break;
-			} else {
-				err = got_error(GOT_ERR_PRIVSEP_MSG);
-				break;
-			}
-		}
-
-		if (imsg.hdr.len < IMSG_HEADER_SIZE + min_datalen) {
-			imsg_free(&imsg);
-			err = got_error(GOT_ERR_PRIVSEP_LEN);
+		err = got_privsep_recv_imsg(&imsg, ibuf, min_datalen);
+		if (err)
 			break;
-		}
 
 		datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
 
@@ -1678,7 +1655,7 @@ got_privsep_recv_tree(struct got_tree_object **tree, s
 		if (err)
 			break;
 	}
-done:
+
 	if (*tree && (*tree)->nentries != nentries) {
 		if (err == NULL)
 			err = got_error(GOT_ERR_PRIVSEP_LEN);