commit 9228a15c477d8ec5797456ed322923d97fd9e92d from: Omar Polo via: Thomas Adam date: Fri Feb 03 15:22:14 2023 UTC got_imsg_fetch_ref: use struct instead of buffer for id ok stsp@ commit - f9f544689c6f4d8dd6dfb97da00ffbaf987ddab4 commit + 9228a15c477d8ec5797456ed322923d97fd9e92d blob - 6a2f4e7414235ad63b95198e47dd00e878cce04c blob + 02292e972104d2b45938f05eead90ec38673777a --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -433,7 +433,7 @@ struct got_imsg_fetch_symrefs { /* Structure for GOT_IMSG_FETCH_REF data. */ struct got_imsg_fetch_ref { /* Describes a reference which will be fetched. */ - uint8_t refid[SHA1_DIGEST_LENGTH]; + struct got_object_id refid; /* Followed by reference name in remaining data of imsg buffer. */ }; blob - e78d9db9fa71b3ce3cd587e874c6e2255d7972fa blob + b41abb0a41e29ff5740a78fd1bc96d414df87fdf --- lib/privsep.c +++ lib/privsep.c @@ -736,7 +736,7 @@ got_privsep_recv_fetch_progress(int *done, struct got_ } break; case GOT_IMSG_FETCH_REF: - if (datalen <= SHA1_DIGEST_LENGTH) { + if (datalen <= sizeof(**id)) { err = got_error(GOT_ERR_PRIVSEP_MSG); break; } @@ -745,9 +745,9 @@ got_privsep_recv_fetch_progress(int *done, struct got_ err = got_error_from_errno("malloc"); break; } - memcpy((*id)->sha1, imsg.data, SHA1_DIGEST_LENGTH); - *refname = strndup(imsg.data + SHA1_DIGEST_LENGTH, - datalen - SHA1_DIGEST_LENGTH); + memcpy(*id, imsg.data, sizeof(**id)); + *refname = strndup(imsg.data + sizeof(**id), + datalen - sizeof(**id)); if (*refname == NULL) { err = got_error_from_errno("strndup"); break; blob - bc787d9884c4a2f26911098698dd62a16e7d308f blob + 128d3e0a4647f42c0d2701eacd6645d0791195ff --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -281,7 +281,7 @@ send_fetch_ref(struct imsgbuf *ibuf, struct got_object return got_error_from_errno("imsg_create FETCH_REF"); /* Keep in sync with struct got_imsg_fetch_ref definition! */ - if (imsg_add(wbuf, refid->sha1, SHA1_DIGEST_LENGTH) == -1) + if (imsg_add(wbuf, refid, sizeof(*refid)) == -1) return got_error_from_errno("imsg_add FETCH_REF"); if (imsg_add(wbuf, refname, reflen) == -1) return got_error_from_errno("imsg_add FETCH_REF");