Subject: Re: [PATCH v7 2/5] commit.c/GPG signature verification: Also look at the first GPG status line

From: John Keeping <[email-masked]>
Date: Sun, 31 Mar 2013 15:41:28 +0100

On Sun, Mar 31, 2013 at 04:32:52PM +0200, Sebastian Götte wrote:
> 
> Signed-off-by: Sebastian Götte <[email-masked]>
> ---
>  commit.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/commit.c b/commit.c
> index eb645af..eda7f90 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -1027,8 +1027,8 @@ static struct {
>  	char result;
>  	const char *check;
>  } sigcheck_gpg_status[] = {
> -	{ 'G', "\n[GNUPG:] GOODSIG " },
> -	{ 'B', "\n[GNUPG:] BADSIG " },
> +	{ 'G', "[GNUPG:] GOODSIG " },
> +	{ 'B', "[GNUPG:] BADSIG " },
>  };
>  
>  static void parse_gpg_output(struct signature_check *sigc)
> @@ -1036,13 +1036,20 @@ static void parse_gpg_output(struct signature_check *sigc)
>  	const char *buf = sigc->gpg_status;
>  	int i;
>  
> +	/* Iterate over all search strings */
>  	for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
> -		const char *found = strstr(buf, sigcheck_gpg_status[i].check);
> -		const char *next;
> -		if (!found)
> -			continue;
> +		const char *found, *next;
> +
> +		if (!prefixcmp(buf, sigcheck_gpg_status[i].check + 1)) {
> +			/* At the very beginning of the buffer */

This seems wrong.  You're losing the "\n" in front of the status strings
above but adding a special first line check skipping the first
character.  Surely it should be one of these changes or the other, not
both?

> +			found = buf + strlen(sigcheck_gpg_status[i].check + 1);
> +		} else {
> +			found = strstr(buf, sigcheck_gpg_status[i].check);
> +			if (!found)
> + 				continue;
> +			found += strlen(sigcheck_gpg_status[i].check);
> +		}
>  		sigc->result = sigcheck_gpg_status[i].result;
> -		found += strlen(sigcheck_gpg_status[i].check);
>  		sigc->key = xmemdupz(found, 16);
>  		found += 17;
>  		next = strchrnul(found, '\n');
> -- 
> 1.8.1.5