Subject: Re: [PATCH 1/5] gpg-interface: simplify ssh fingerprint parsing

From: Junio C Hamano <[email-masked]>
Date: Tue, 28 Oct 2025 09:45:12 -0700

Christian Couder <[email-masked]> writes:

> In "gpg-interface.c", the 'parse_ssh_output()' function takes a
> 'struct signature_check *sigc' argument and populates many members of
> this 'sigc' using information parsed from 'sigc->output' which
> contains the ouput of an `ssh-keygen -Y ...` command that was used to
> verify an SSH signature.
>
> When it populates 'sigc->fingerprint' though, it uses
> `xstrdup(strstr(line, "key ") + 4)` while `strstr(line, "key ")` has
> already been computed a few lines above and is already available in
> the `key` variable.
>
> Let's simplify this.
>
> Signed-off-by: Christian Couder <[email-masked]>
> ---
>  gpg-interface.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gpg-interface.c b/gpg-interface.c
> index 2f4f0e32cb..91d1b58cb4 100644
> --- a/gpg-interface.c
> +++ b/gpg-interface.c
> @@ -443,7 +443,7 @@ static void parse_ssh_output(struct signature_check *sigc)
>  
>  	key = strstr(line, "key ");
>  	if (key) {
> -		sigc->fingerprint = xstrdup(strstr(line, "key ") + 4);
> +		sigc->fingerprint = xstrdup(key + 4);

Looks like an obvious avoidance of duplicated work.  I am not sure
if "find 'key ' anywhere on the line and take the first one" is a
sensible validation, but that is not a fault of this patch ;-)

>  		sigc->key = xstrdup(sigc->fingerprint);
>  	} else {
>  		/*