commit e4c85b49900b1c456739094cbe3af00249fa6029 from: Omar Polo via: Thomas Adam date: Fri Feb 03 15:22:14 2023 UTC got_imsg_commit_object: use struct instead of buffer for id ok stsp@ commit - fc842fc8042ddce403d11cfeca3d40c6e80cc2f3 commit + e4c85b49900b1c456739094cbe3af00249fa6029 blob - 9848199ea0f505dd27688d8bbcb0d9825a1f3ed9 blob + d45c856b23421ee688bc12134960d91d40572e28 --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -233,7 +233,7 @@ struct got_imsg_object { /* Structure for GOT_IMSG_COMMIT data. */ struct got_imsg_commit_object { - uint8_t tree_id[SHA1_DIGEST_LENGTH]; + struct got_object_id tree_id; size_t author_len; time_t author_time; time_t author_gmtoff; @@ -247,7 +247,7 @@ struct got_imsg_commit_object { * Followed by author_len + committer_len data bytes */ - /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */ + /* Followed by 'nparents' struct got_object_id */ /* * Followed by 'logmsg_len' bytes of commit log message data in blob - 9a07b1a40063226ca288a0a32e223888e7d00065 blob + 37ac68ccbb1740fcf71e6275e0713de0e5ede681 --- lib/privsep.c +++ lib/privsep.c @@ -1203,15 +1203,14 @@ got_privsep_send_commit(struct imsgbuf *ibuf, struct g size_t logmsg_len = strlen(commit->logmsg); total = sizeof(*icommit) + author_len + committer_len + - commit->nparents * SHA1_DIGEST_LENGTH; + commit->nparents * sizeof(struct got_object_id); buf = malloc(total); if (buf == NULL) return got_error_from_errno("malloc"); icommit = (struct got_imsg_commit_object *)buf; - memcpy(icommit->tree_id, commit->tree_id->sha1, - sizeof(icommit->tree_id)); + memcpy(&icommit->tree_id, commit->tree_id, sizeof(icommit->tree_id)); icommit->author_len = author_len; icommit->author_time = commit->author_time; icommit->author_gmtoff = commit->author_gmtoff; @@ -1227,8 +1226,8 @@ got_privsep_send_commit(struct imsgbuf *ibuf, struct g memcpy(buf + len, commit->committer, committer_len); len += committer_len; STAILQ_FOREACH(qid, &commit->parent_ids, entry) { - memcpy(buf + len, &qid->id, SHA1_DIGEST_LENGTH); - len += SHA1_DIGEST_LENGTH; + memcpy(buf + len, &qid->id, sizeof(qid->id)); + len += sizeof(qid->id); } if (imsg_compose(ibuf, GOT_IMSG_COMMIT, 0, 0, -1, buf, len) == -1) { @@ -1263,7 +1262,7 @@ get_commit_from_imsg(struct got_commit_object **commit icommit = imsg->data; if (datalen != sizeof(*icommit) + icommit->author_len + icommit->committer_len + - icommit->nparents * SHA1_DIGEST_LENGTH) + icommit->nparents * sizeof(struct got_object_id)) return got_error(GOT_ERR_PRIVSEP_LEN); if (icommit->nparents < 0) @@ -1276,8 +1275,8 @@ get_commit_from_imsg(struct got_commit_object **commit return got_error_from_errno( "got_object_commit_alloc_partial"); - memcpy((*commit)->tree_id->sha1, icommit->tree_id, - SHA1_DIGEST_LENGTH); + memcpy((*commit)->tree_id, &icommit->tree_id, + sizeof(icommit->tree_id)); (*commit)->author_time = icommit->author_time; (*commit)->author_gmtoff = icommit->author_gmtoff; (*commit)->committer_time = icommit->committer_time; @@ -1342,7 +1341,7 @@ get_commit_from_imsg(struct got_commit_object **commit if (err) break; memcpy(&qid->id, imsg->data + len + - i * SHA1_DIGEST_LENGTH, sizeof(qid->id)); + i * sizeof(qid->id), sizeof(qid->id)); STAILQ_INSERT_TAIL(&(*commit)->parent_ids, qid, entry); (*commit)->nparents++; }