From ccd76e6494ba2c502c90e38e51ca9a4eb21689bb Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 27 Jun 2022 07:31:31 -0500 Subject: gpg: fix error handling during decryption An non-zero exit code from the execution of gpg during decryption would prevent aerc from parsing the output of gpg. The output should always be parsed. Gpg can exit with an error due to not being able to validate a signature. Aerc handles this error with the UI, and therefore all output should be parsed regardless of exit state of gpg. The parsing of stdout will find the errors and report back to aerc properly. Signed-off-by: Tim Culverhouse Acked-by: Moritz Poldrack --- lib/crypto/gpg/gpgbin/decrypt.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/crypto/gpg') diff --git a/lib/crypto/gpg/gpgbin/decrypt.go b/lib/crypto/gpg/gpgbin/decrypt.go index fd11b75..0962630 100644 --- a/lib/crypto/gpg/gpgbin/decrypt.go +++ b/lib/crypto/gpg/gpgbin/decrypt.go @@ -18,7 +18,11 @@ func Decrypt(r io.Reader) (*models.MessageDetails, error) { } args := []string{"--decrypt"} g := newGpg(bytes.NewReader(orig), args) - err = g.cmd.Run() + _ = g.cmd.Run() + outRdr := bytes.NewReader(g.stdout.Bytes()) + // Always parse stdout, even if there was an error running command. + // We'll find the error in the parsing + err = parse(outRdr, md) if err != nil { err = parseError(g.stderr.String()) switch GPGErrors[err.Error()] { @@ -29,7 +33,5 @@ func Decrypt(r io.Reader) (*models.MessageDetails, error) { return nil, err } } - outRdr := bytes.NewReader(g.stdout.Bytes()) - parse(outRdr, md) return md, nil } -- cgit v1.2.3