"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: use proper type for got_imsg_enumerated_commit
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Wed, 10 Jul 2024 20:40:07 +0200

Download raw body.

Thread
On Wed, Jul 10, 2024 at 06:22:13PM +0200, Omar Polo wrote:
> in this case there's also an existing math error in privsep.c while
> computing the size of the imsg: sizeof(struct ...) already accounts for
> the hash digest, so no need to add to it.
> 
> commit 259994d85b8a255b5d9b1176870695cd5350bb19 (main)
> from: Omar Polo <op@omarpolo.com>
> date: Wed Jul 10 16:15:14 2024 UTC
>  
>  use proper type for got_imsg_enumerated_commit

ok

>  
> diff 0f9ed2af036df203ad7b7e5b7e54756bf36a7c4c 259994d85b8a255b5d9b1176870695cd5350bb19
> commit - 0f9ed2af036df203ad7b7e5b7e54756bf36a7c4c
> commit + 259994d85b8a255b5d9b1176870695cd5350bb19
> blob - 86c780f1b39bd6593b1deb94215ecf9405b05740
> blob + 7511786325d8e67359b25d6e5a6983eaf0f84457
> --- lib/got_lib_privsep.h
> +++ lib/got_lib_privsep.h
> @@ -592,7 +592,7 @@ struct got_imsg_traversed_commits {
>  
>  /* Structure for GOT_IMSG_ENUMERATED_COMMIT  */
>  struct got_imsg_enumerated_commit {
> -	uint8_t id[SHA1_DIGEST_LENGTH];
> +	struct got_object_id id;
>  	time_t mtime;
>  } __attribute__((__packed__));
>  
> blob - 337a7e73209bcce74e47b6f588ebc9eef0119ae9
> blob + e51908c9bc07441fc896089ee1c96ad436e9c94a
> --- lib/privsep.c
> +++ lib/privsep.c
> @@ -2824,12 +2824,12 @@ got_privsep_send_enumerated_commit(struct imsgbuf *ibu
>  	struct ibuf *wbuf;
>  
>  	wbuf = imsg_create(ibuf, GOT_IMSG_ENUMERATED_COMMIT, 0, 0,
> -	    sizeof(struct got_imsg_enumerated_commit) + SHA1_DIGEST_LENGTH);
> +	    sizeof(struct got_imsg_enumerated_commit));
>  	if (wbuf == NULL)
>  		return got_error_from_errno("imsg_create ENUMERATED_COMMIT");
>  
>  	/* Keep in sync with struct got_imsg_enumerated_commit! */
> -	if (imsg_add(wbuf, id, SHA1_DIGEST_LENGTH) == -1)
> +	if (imsg_add(wbuf, id, sizeof(*id)) == -1)
>  		return got_error_from_errno("imsg_add ENUMERATED_COMMIT");
>  	if (imsg_add(wbuf, &mtime, sizeof(mtime)) == -1)
>  		return got_error_from_errno("imsg_add ENUMERATED_COMMIT");
> @@ -2880,7 +2880,7 @@ got_privsep_recv_enumerated_objects(int *found_all_obj
>  				break;
>  			}
>  			icommit = (struct got_imsg_enumerated_commit *)imsg.data;
> -			memcpy(commit_id.sha1, icommit->id, SHA1_DIGEST_LENGTH);
> +			memcpy(&commit_id, &icommit->id, sizeof(commit_id));
>  			mtime = icommit->mtime;
>  			have_commit = 1;
>  			break;
> 
>