Skip to content

Commit 8b44b2b

Browse files
peffgitster
authored andcommitted
gpg-interface: find the last gpg signature line
A signed tag has a detached signature like this: object ... [...more header...] This is the tag body. -----BEGIN PGP SIGNATURE----- [opaque gpg data] -----END PGP SIGNATURE----- Our parser finds the _first_ line that appears to start a PGP signature block, meaning we may be confused by a signature (or a signature-like line) in the actual body. Let's keep parsing and always find the final block, which should be the detached signature over all of the preceding content. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Ben Toews <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f68f2dd commit 8b44b2b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

gpg-interface.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ static int is_gpg_start(const char *line)
110110
size_t parse_signature(const char *buf, size_t size)
111111
{
112112
size_t len = 0;
113-
while (len < size && !is_gpg_start(buf + len)) {
114-
const char *eol = memchr(buf + len, '\n', size - len);
113+
size_t match = size;
114+
while (len < size) {
115+
const char *eol;
116+
117+
if (is_gpg_start(buf + len))
118+
match = len;
119+
120+
eol = memchr(buf + len, '\n', size - len);
115121
len += eol ? eol - (buf + len) + 1 : size - len;
116122
}
117-
return len;
123+
return match;
118124
}
119125

120126
void set_signing_key(const char *key)

t/t7004-tag.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,17 @@ test_expect_success GPG \
10591059
git tag -v blanknonlfile-signed-tag
10601060
'
10611061

1062+
test_expect_success GPG 'signed tag with embedded PGP message' '
1063+
cat >msg <<-\EOF &&
1064+
-----BEGIN PGP MESSAGE-----
1065+
1066+
this is not a real PGP message
1067+
-----END PGP MESSAGE-----
1068+
EOF
1069+
git tag -s -F msg confusing-pgp-message &&
1070+
git tag -v confusing-pgp-message
1071+
'
1072+
10621073
# messages with commented lines for signed tags:
10631074

10641075
cat >sigcommentsfile <<EOF

0 commit comments

Comments
 (0)