From: Omar Polo Subject: struct instead of buffer for got_imsg_send_{,remote_}ref To: gameoftrees@openbsd.org Date: Wed, 01 Feb 2023 09:56:49 +0100 usual dance; fetch.sh and send.sh fully passes. diff 05db677d577e42756e296c0262a02c65bfd614fb refs/heads/w commit - 05db677d577e42756e296c0262a02c65bfd614fb commit + f2f9d6049f560b07591f71ccccdb8eed2f5022a4 blob - 6a64f1edca2e533d797c2fc7ebd6e8d738023fa4 blob + 151e0d73fa443289c8609863654c6bef6d128723 --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -458,7 +458,7 @@ struct got_imsg_send_ref { /* Structure for GOT_IMSG_SEND_REF data. */ struct got_imsg_send_ref { - uint8_t id[SHA1_DIGEST_LENGTH]; + struct got_object_id id; int delete; size_t name_len; /* Followed by name_len data bytes. */ @@ -466,7 +466,7 @@ struct got_imsg_send_remote_ref { /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */ struct got_imsg_send_remote_ref { - uint8_t id[SHA1_DIGEST_LENGTH]; + struct got_object_id id; size_t name_len; /* Followed by name_len data bytes. */ } __attribute__((__packed__)); blob - 16a24da99f408f5487194b9f4ff88b84b5add165 blob + 970978560467422ed3a634b6c3b86e48e6b49fd0 --- lib/privsep.c +++ lib/privsep.c @@ -816,7 +816,7 @@ send_send_ref(const char *name, size_t name_len, struc return got_error_from_errno("imsg_create SEND_REF"); /* Keep in sync with struct got_imsg_send_ref! */ - if (imsg_add(wbuf, id->sha1, sizeof(id->sha1)) == -1) + if (imsg_add(wbuf, id, sizeof(*id)) == -1) return got_error_from_errno("imsg_add SEND_REF"); if (imsg_add(wbuf, &delete, sizeof(delete)) == -1) return got_error_from_errno("imsg_add SEND_REF"); @@ -918,7 +918,7 @@ got_privsep_recv_send_remote_refs(struct got_pathlist_ err = got_error_from_errno("malloc"); goto done; } - memcpy(id->sha1, iremote_ref.id, SHA1_DIGEST_LENGTH); + memcpy(id, &iremote_ref.id, sizeof(*id)); refname = strndup(imsg.data + sizeof(iremote_ref), datalen - sizeof(iremote_ref)); if (refname == NULL) { blob - 40b31c00d9ba7fd602c0df52657c1340c932af57 blob + 0fd0e6b2e84bfc5519482bd5ae802897596069f2 --- libexec/got-send-pack/got-send-pack.c +++ libexec/got-send-pack/got-send-pack.c @@ -206,7 +206,7 @@ send_their_ref(struct imsgbuf *ibuf, struct got_object return got_error_from_errno("imsg_create SEND_REMOTE_REF"); /* Keep in sync with struct got_imsg_send_remote_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 SEND_REMOTE_REF"); if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1) return got_error_from_errno("imsg_add SEND_REMOTE_REF"); @@ -704,7 +704,7 @@ main(int argc, char **argv) err = got_error_from_errno("malloc"); goto done; } - memcpy(id->sha1, href.id, SHA1_DIGEST_LENGTH); + memcpy(id, &href.id, sizeof(*id)); if (href.delete) err = got_pathlist_append(&delete_refs, refname, id); else