commit ef53e23c28efc2b91e6a2fbbb3a1e914a895745d from: Stefan Sperling via: Thomas Adam date: Thu Jun 23 14:09:34 2022 UTC fix a bug in got_privsep_send_object_idlist() exposed by recent changes The old code did not work correctly if only a single object Id was to be sent to got-read-pack. Make got-read-pack error out if the list of commits for object enumeration is empty to catch this problem if it occurs again. Found by the send_basic test, which was failing with GOT_TEST_PACK=1 ok tracey commit - e71f1e62ddab990a047fe827d13b25003a9b8014 commit + ef53e23c28efc2b91e6a2fbbb3a1e914a895745d blob - f6f70cc0eaf2082147dd6cfcf7da7c1a010486f9 blob + 9f0391a5a0df224883bdd06c95d2616df77b84d1 --- lib/privsep.c +++ lib/privsep.c @@ -3118,21 +3118,21 @@ got_privsep_send_object_idlist(struct imsgbuf *ibuf, { const struct got_error *err = NULL; struct got_object_id *idlist[GOT_IMSG_OBJ_ID_LIST_MAX_NIDS]; - int i, j = 0; + int i, queued = 0; for (i = 0; i < nids; i++) { - j = i % nitems(idlist); - idlist[j] = ids[i]; - if (j >= nitems(idlist) - 1) { - err = send_idlist(ibuf, idlist, j + 1); + idlist[i % nitems(idlist)] = ids[i]; + queued++; + if (queued >= nitems(idlist) - 1) { + err = send_idlist(ibuf, idlist, queued); if (err) return err; - j = 0; + queued = 0; } } - if (j > 0) { - err = send_idlist(ibuf, idlist, j + 1); + if (queued > 0) { + err = send_idlist(ibuf, idlist, queued); if (err) return err; } blob - ccb6ab4e634be903e2e13bc07de7e337b68652ad blob + 7a94b98c4e2736937f27044f9925a49eb5459d1a --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -1387,6 +1387,11 @@ enumeration_request(struct imsg *imsg, struct imsgbuf if (err) goto done; + if (STAILQ_EMPTY(&commit_ids)) { + err = got_error(GOT_ERR_PRIVSEP_MSG); + goto done; + } + err = recv_object_ids(idset, ibuf); if (err) goto done;