summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-06-27 07:31:31 -0500
committerRobin Jarry <robin@jarry.cc>2022-06-28 22:00:04 +0200
commitccd76e6494ba2c502c90e38e51ca9a4eb21689bb (patch)
treeda96a444d0e3c3ca16b48d80a1e27ec25be6a7cd
parent506f8f165c4c7de59255c5691ecef9f95dea5254 (diff)
downloadaerc-ccd76e6494ba2c502c90e38e51ca9a4eb21689bb.zip
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 <tim@timculverhouse.com> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
-rw-r--r--lib/crypto/gpg/gpgbin/decrypt.go8
1 files changed, 5 insertions, 3 deletions
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
}