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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: fix ref parsing for sha256
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Fri, 12 Jul 2024 09:17:29 +0200

Download raw body.

Thread
On Thu, Jul 11, 2024 at 03:40:28PM +0200, Omar Polo wrote:
> This is another place where we shouldn't hardcode the
> SH1_DIGEST_LENGTH_STRING.  ok?

ok

> 
> diff /home/op/w/got
> commit - 020f73dba5df9e319726af7526dbb3b478d52b76
> path + /home/op/w/got
> blob - 070b80df0cce4e90b81489df1c9f71ce5c1c3cc7
> file + lib/reference.c
> --- lib/reference.c
> +++ lib/reference.c
> @@ -298,8 +298,10 @@ parse_packed_ref_line(struct got_reference **ref, cons
>  {
>  	struct got_object_id id;
>  	const char *name;
> +	size_t idlen;
>  
>  	*ref = NULL;
> +	idlen = got_hash_digest_string_length(algo);
>  
>  	if (line[0] == '#' || line[0] == '^')
>  		return NULL;
> @@ -308,11 +310,11 @@ parse_packed_ref_line(struct got_reference **ref, cons
>  		return got_error(GOT_ERR_BAD_REF_DATA);
>  
>  	if (abs_refname) {
> -		if (strcmp(line + SHA1_DIGEST_STRING_LENGTH, abs_refname) != 0)
> +		if (strcmp(line + idlen, abs_refname) != 0)
>  			return NULL;
>  		name = abs_refname;
>  	} else
> -		name = line + SHA1_DIGEST_STRING_LENGTH;
> +		name = line + idlen;
>  
>  	return alloc_ref(ref, name, &id, GOT_REF_IS_PACKED, mtime);
>  }
> 
>