Skip to content

Commit efee955

Browse files
Michael J Grubergitster
authored andcommitted
gpg-interface: check gpg signature creation status
When we create a signature, it may happen that gpg returns with "success" but not with an actual detached signature on stdout. Check for the correct signature creation status to catch these cases better. Really, --status-fd parsing is the only way to check gpg status reliably. We do the same for verify already. Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0581b54 commit efee955

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

gpg-interface.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
153153
struct child_process gpg = CHILD_PROCESS_INIT;
154154
int ret;
155155
size_t i, j, bottom;
156+
struct strbuf gpg_status = STRBUF_INIT;
156157

157158
argv_array_pushl(&gpg.args,
158159
gpg_program,
160+
"--status-fd=2",
159161
"-bsau", signing_key,
160162
NULL);
161163

@@ -167,10 +169,12 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
167169
*/
168170
sigchain_push(SIGPIPE, SIG_IGN);
169171
ret = pipe_command(&gpg, buffer->buf, buffer->len,
170-
signature, 1024, NULL, 0);
172+
signature, 1024, &gpg_status, 0);
171173
sigchain_pop(SIGPIPE);
172174

173-
if (ret || signature->len == bottom)
175+
ret |= !strstr(gpg_status.buf, "\n[GNUPG:] SIG_CREATED ");
176+
strbuf_release(&gpg_status);
177+
if (ret)
174178
return error(_("gpg failed to sign the data"));
175179

176180
/* Strip CR from the line endings, in case we are on Windows. */

t/t7004-tag.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,10 +1202,17 @@ test_expect_success GPG,RFC1991 \
12021202
# try to sign with bad user.signingkey
12031203
git config user.signingkey BobTheMouse
12041204
test_expect_success GPG \
1205-
'git tag -s fails if gpg is misconfigured' \
1205+
'git tag -s fails if gpg is misconfigured (bad key)' \
12061206
'test_must_fail git tag -s -m tail tag-gpg-failure'
12071207
git config --unset user.signingkey
12081208

1209+
# try to produce invalid signature
1210+
test_expect_success GPG \
1211+
'git tag -s fails if gpg is misconfigured (bad signature format)' \
1212+
'test_config gpg.program echo &&
1213+
test_must_fail git tag -s -m tail tag-gpg-failure'
1214+
1215+
12091216
# try to verify without gpg:
12101217

12111218
rm -rf gpghome

0 commit comments

Comments
 (0)