Skip to content

Commit a77944a

Browse files
committed
Unbreak interactive GPG prompt upon signing
With the recent update in efee955 (gpg-interface: check gpg signature creation status, 2016-06-17), we ask GPG to send all status updates to stderr, and then catch the stderr in an strbuf. But GPG might fail, and send error messages to stderr. And we simply do not show them to the user. Even worse: this swallows any interactive prompt for a passphrase. And detaches stderr from the tty so that the passphrase cannot be read. So while the first problem could be fixed (by printing the captured stderr upon error), the second problem cannot be easily fixed, and presents a major regression. So let's just revert commit efee955. This fixes #871 Cc: Michael J Gruber <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7a21b9d commit a77944a

File tree

2 files changed

+3
-49
lines changed

2 files changed

+3
-49
lines changed

gpg-interface.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
972972
struct child_process gpg = CHILD_PROCESS_INIT;
973973
int ret;
974974
size_t bottom;
975-
const char *cp;
976-
struct strbuf gpg_status = STRBUF_INIT;
977975

978976
strvec_pushl(&gpg.args,
979977
use_format->program,
980-
"--status-fd=2",
981978
"-bsau", signing_key,
982979
NULL);
983980

@@ -989,23 +986,11 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
989986
*/
990987
sigchain_push(SIGPIPE, SIG_IGN);
991988
ret = pipe_command(&gpg, buffer->buf, buffer->len,
992-
signature, 1024, &gpg_status, 0);
989+
signature, 1024, NULL, 0);
993990
sigchain_pop(SIGPIPE);
994991

995-
for (cp = gpg_status.buf;
996-
cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
997-
cp++) {
998-
if (cp == gpg_status.buf || cp[-1] == '\n')
999-
break; /* found */
1000-
}
1001-
ret |= !cp;
1002-
if (ret) {
1003-
error(_("gpg failed to sign the data:\n%s"),
1004-
gpg_status.len ? gpg_status.buf : "(no gpg output)");
1005-
strbuf_release(&gpg_status);
1006-
return -1;
1007-
}
1008-
strbuf_release(&gpg_status);
992+
if (ret || signature->len == bottom)
993+
return error(_("gpg failed to sign the data"));
1009994

1010995
/* Strip CR from the line endings, in case we are on Windows. */
1011996
remove_cr_after(signature, bottom);

t/t7004-tag.sh

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,44 +1517,13 @@ test_expect_success GPG \
15171517
'test_config user.signingkey BobTheMouse &&
15181518
test_must_fail git tag -s -m tail tag-gpg-failure'
15191519

1520-
# try to produce invalid signature
1521-
test_expect_success GPG \
1522-
'git tag -s fails if gpg is misconfigured (bad signature format)' \
1523-
'test_config gpg.program echo &&
1524-
test_must_fail git tag -s -m tail tag-gpg-failure'
1525-
1526-
# try to produce invalid signature
1527-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1528-
git tag -s -m tail tag-gpg-double-sig &&
1529-
git cat-file tag tag-gpg-double-sig >tag &&
1530-
othersigheader=$(test_oid othersigheader) &&
1531-
sed -ne "/^\$/q;p" tag >new-tag &&
1532-
cat <<-EOM >>new-tag &&
1533-
$othersigheader -----BEGIN PGP SIGNATURE-----
1534-
someinvaliddata
1535-
-----END PGP SIGNATURE-----
1536-
EOM
1537-
sed -e "1,/^tagger/d" tag >>new-tag &&
1538-
new_tag=$(git hash-object -t tag -w new-tag) &&
1539-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1540-
git verify-tag tag-gpg-double-sig &&
1541-
git fsck
1542-
'
1543-
15441520
# try to sign with bad user.signingkey
15451521
test_expect_success GPGSM \
15461522
'git tag -s fails if gpgsm is misconfigured (bad key)' \
15471523
'test_config user.signingkey BobTheMouse &&
15481524
test_config gpg.format x509 &&
15491525
test_must_fail git tag -s -m tail tag-gpg-failure'
15501526

1551-
# try to produce invalid signature
1552-
test_expect_success GPGSM \
1553-
'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1554-
'test_config gpg.x509.program echo &&
1555-
test_config gpg.format x509 &&
1556-
test_must_fail git tag -s -m tail tag-gpg-failure'
1557-
15581527
# try to verify without gpg:
15591528

15601529
rm -rf gpghome

0 commit comments

Comments
 (0)