public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: "Sebastian Götte" <jaseg@physik•tu-berlin.de>
Cc: git@vger•kernel.org
Subject: Re: [PATCH v4 2/5] commit.c/GPG signature verification: Also look at the first GPG status line
Date: Thu, 28 Mar 2013 15:33:01 -0700	[thread overview]
Message-ID: <7v620brw82.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <51518106.6060804@physik.tu-berlin.de> ("Sebastian Götte"'s message of "Tue, 26 Mar 2013 12:05:42 +0100")

Sebastian Götte <jaseg@physik•tu-berlin.de> writes:

> Signed-off-by: Sebastian Götte <jaseg@physik-pool•tu-berlin.de>
> ---
>  commit.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/commit.c b/commit.c
> index 1aeb17a..533727c 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -1027,8 +1027,8 @@ static struct {
>  	char result;
>  	const char *check;
>  } signature_check[] = {
> -	{ 'G', "\n[GNUPG:] GOODSIG " },
> -	{ 'B', "\n[GNUPG:] BADSIG " },
> +	{ 'G', "[GNUPG:] GOODSIG " },
> +	{ 'B', "[GNUPG:] BADSIG " },
>  };
>  
>  static void parse_signature_lines(struct signature *sig)
> @@ -1041,6 +1041,9 @@ static void parse_signature_lines(struct signature *sig)
>  		const char *next;
>  		if (!found)
>  			continue;
> +		if (found != buf) 
> +			if (found[-1] != '\n')
> +				continue;

It would be much easier to read if it were "unless we are not
looking at the very first byte, the previous byte must be LF", i.e.

	if (found != buf && found[-1] != '\n')

Is that continue correct?  Don't you want to retry from the end of
the line that contains the mistaken hit?

The "\n" at the beginning anchors the expected string for quicker
multi-line scan done with strstr().  If you really want to lose that
LF and still write this function correctly and clearly, I think you
would need to iterate over the buffer line by line.

What you want to do may be more like this, I think.

 commit.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/commit.c b/commit.c
index d093c9c..d6e0b00 100644
--- a/commit.c
+++ b/commit.c
@@ -1045,8 +1045,8 @@ static struct {
 	char result;
 	const char *check;
 } signature_check[] = {
-	{ 'G', "[GNUPG:] GOODSIG " },
-	{ 'B', "[GNUPG:] BADSIG " },
+	{ 'G', "\n[GNUPG:] GOODSIG " },
+	{ 'B', "\n[GNUPG:] BADSIG " },
 };
 
 static void parse_signature_lines(struct signature *sig)
@@ -1055,15 +1055,18 @@ static void parse_signature_lines(struct signature *sig)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(signature_check); i++) {
-		const char *found = strstr(buf, signature_check[i].check);
-		const char *next;
-		if (!found)
-			continue;
-		if (found != buf)
-			if (found[-1] != '\n')
+		const char *found, *next;
+
+		if (!prefixcmp(buf, signature_check[i].check + 1)) {
+			/* At the very beginning of the buffer */
+			found = buf + strlen(signature_check[i].check + 1);
+		} else {
+			found = strstr(buf, signature_check[i].check);
+			if (!found)
 				continue;
+			found +=  strlen(signature_check[i].check);
+		}
 		sig->check_result = signature_check[i].result;
-		found += strlen(signature_check[i].check);
 		sig->key = xmemdupz(found, 16);
 		found += 17;
 		next = strchrnul(found, '\n');

  reply	other threads:[~2013-03-28 22:33 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-23  1:57 [PATCH v2 1/4] Move commit GPG signature verification to commit.c Sebastian Götte
2013-03-25 15:54 ` Junio C Hamano
2013-03-25 23:46   ` [PATCH 0/5] Verify GPG signatures when merging and extend %G? pretty string Sebastian Götte
2013-03-26  1:46     ` Junio C Hamano
2013-03-26 11:05       ` [PATCH v4 " Sebastian Götte
2013-03-26 16:26         ` Junio C Hamano
2013-03-26 16:43           ` Sebastian Götte
     [not found]       ` <cover.1364295502.git.jaseg@physik-pool.tu-berlin.de>
2013-03-26 11:05         ` [PATCH v4 1/5] Move commit GPG signature verification to commit.c Sebastian Götte
2013-03-26 11:05         ` [PATCH v4 2/5] commit.c/GPG signature verification: Also look at the first GPG status line Sebastian Götte
2013-03-28 22:33           ` Junio C Hamano [this message]
2013-03-26 11:05         ` [PATCH v4 3/5] merge/pull: verify GPG signatures of commits being merged Sebastian Götte
2013-03-28 22:33           ` Junio C Hamano
2013-03-30  0:13             ` [PATCH v5 0/5] Verify GPG signatures when merging and extend %G? pretty string Sebastian Götte
     [not found]             ` <cover.1364601337.git.jaseg@physik-pool.tu-berlin.de>
2013-03-30  0:14               ` [PATCH v5 1/5] Move commit GPG signature verification to commit.c Sebastian Götte
2013-03-30  3:37                 ` Junio C Hamano
2013-03-30  0:14               ` [PATCH v5 2/5] commit.c/GPG signature verification: Also look at the first GPG status line Sebastian Götte
2013-03-30  3:37                 ` Junio C Hamano
2013-03-30  0:14               ` [PATCH v5 3/5] merge/pull: verify GPG signatures of commits being merged Sebastian Götte
2013-03-30  3:38                 ` Junio C Hamano
2013-03-30 14:14                   ` [PATCH v6 0/5] Verify GPG signatures when merging and extend %G? pretty string Sebastian Götte
     [not found]                   ` <cover.1364652339.git.jaseg@physik-pool.tu-berlin.de>
2013-03-30 14:15                     ` [PATCH v6 1/5] Move commit GPG signature verification to commit.c Sebastian Götte
2013-03-30 14:15                     ` [PATCH v6 2/5] commit.c/GPG signature verification: Also look at the first GPG status line Sebastian Götte
2013-03-30 14:15                     ` [PATCH v6 3/5] merge/pull: verify GPG signatures of commits being merged Sebastian Götte
2013-03-30 14:16                     ` [PATCH v6 4/5] merge/pull Check for untrusted good GPG signatures Sebastian Götte
2013-03-30 14:16                     ` [PATCH v6 5/5] pretty printing: extend %G? to include 'N' and 'U' Sebastian Götte
2013-03-30  0:14               ` [PATCH v5 4/5] merge/pull Check for untrusted good GPG signatures Sebastian Götte
2013-03-31  8:32                 ` Thomas Rast
2013-03-31 10:55                   ` Sebastian Götte
2013-03-31 11:38                     ` Thomas Rast
2013-03-31 11:57                       ` Sebastian Götte
2013-03-31 12:16                         ` Thomas Rast
2013-03-31 12:27                           ` Sebastian Götte
2013-03-31 13:33                             ` John Keeping
2013-03-31 14:32                               ` [PATCH v7 0/5] Verify GPG signatures when merging and extend %G? pretty string Sebastian Götte
     [not found]                               ` <cover.1364738348.git.jaseg@physik-pool.tu-berlin.de>
2013-03-31 14:32                                 ` [PATCH v7 1/5] Move commit GPG signature verification to commit.c Sebastian Götte
2013-03-31 14:32                                 ` [PATCH v7 2/5] commit.c/GPG signature verification: Also look at the first GPG status line Sebastian Götte
2013-03-31 14:41                                   ` John Keeping
2013-03-31 14:33                                 ` [PATCH v7 3/5] merge/pull: verify GPG signatures of commits being merged Sebastian Götte
2013-03-31 14:33                                 ` [PATCH v7 4/5] merge/pull Check for untrusted good GPG signatures Sebastian Götte
2013-03-31 14:44                                   ` John Keeping
2013-03-31 15:03                                     ` Thomas Rast
2013-03-31 15:21                                       ` Sebastian Götte
2013-03-31 15:27                                         ` Thomas Rast
2013-03-31 15:26                                       ` John Keeping
2013-03-31 15:58                                     ` [PATCH v8 0/5] Verify GPG signatures when merging and extend %G? pretty string Sebastian Götte
     [not found]                                     ` <cover.1364742659.git.jaseg@physik-pool.tu-berlin.de>
2013-03-31 16:00                                       ` [PATCH v8 1/5] Move commit GPG signature verification to commit.c Sebastian Götte
2013-03-31 16:01                                       ` [PATCH v8 2/5] commit.c/GPG signature verification: Also look at the first GPG status line Sebastian Götte
2013-03-31 16:02                                       ` [PATCH v8 3/5] merge/pull: verify GPG signatures of commits being merged Sebastian Götte
2013-04-01  2:47                                         ` Junio C Hamano
2013-04-01 12:53                                           ` Sebastian Götte
2013-04-01 14:55                                             ` Junio C Hamano
2013-03-31 16:02                                       ` [PATCH v8 4/5] merge/pull Check for untrusted good GPG signatures Sebastian Götte
2013-03-31 16:03                                       ` [PATCH v8 5/5] pretty printing: extend %G? to include 'N' and 'U' Sebastian Götte
2013-03-31 14:34                                 ` [PATCH v7 " Sebastian Götte
2013-03-30  0:15               ` [PATCH v5 " Sebastian Götte
2013-03-26 11:05         ` [PATCH v4 4/5] merge/pull Check for untrusted good GPG signatures Sebastian Götte
2013-03-26 11:05         ` [PATCH v4 5/5] pretty printing: extend %G? to include 'N' and 'U' Sebastian Götte
     [not found]   ` <cover.1364254748.git.jaseg@physik-pool.tu-berlin.de>
2013-03-25 23:46     ` [PATCH 1/5] Move commit GPG signature verification to commit.c Sebastian Götte
2013-03-25 23:46     ` [PATCH 2/5] commit.c/GPG signature verification: Also look at the first GPG status line Sebastian Götte
2013-03-25 23:46     ` [PATCH 3/5] merge/pull: verify GPG signatures of commits being merged Sebastian Götte
2013-03-25 23:46     ` [PATCH 4/5] merge/pull Check for untrusted good GPG signatures Sebastian Götte
2013-03-25 23:46     ` [PATCH 5/5] pretty printing: extend %G? to include 'N' and 'U' Sebastian Götte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v620brw82.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=jaseg@physik$(echo .)tu-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox