From 80f90c0d41858ddc80232965ce85c8e560a78fbd Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Fri, 1 Jul 2022 19:11:33 +0200 Subject: [PATCH] gpg: fix panic when signing an unparsable message Fix the following error: panic() runtime/panic.go:838 bytes.(*Buffer).ReadFrom() bytes/buffer.go:204 io.copyBuffer() io/io.go:412 io.Copy() io/io.go:385 git.sr.ht/~rjarry/aerc/lib/crypto/gpg/gpgbin.Sign() git.sr.ht/~rjarry/aerc/lib/crypto/gpg/gpgbin/sign.go:25 git.sr.ht/~rjarry/aerc/lib/crypto/gpg.(*Signer).Close() git.sr.ht/~rjarry/aerc/lib/crypto/gpg/writer.go:52 git.sr.ht/~rjarry/aerc/lib/crypto/gpg.multiCloser.Close() git.sr.ht/~rjarry/aerc/lib/crypto/gpg/writer.go:92 git.sr.ht/~rjarry/aerc/widgets.(*Composer).WriteMessage() git.sr.ht/~rjarry/aerc/widgets/compose.go:601 git.sr.ht/~rjarry/aerc/commands/compose.Send.Execute.func1() git.sr.ht/~rjarry/aerc/commands/compose/send.go:127 Fixes: https://todo.sr.ht/~rjarry/aerc/53 Signed-off-by: Moritz Poldrack Acked-by: Tim Culverhouse --- lib/crypto/gpg/gpgbin/sign.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/crypto/gpg/gpgbin/sign.go b/lib/crypto/gpg/gpgbin/sign.go index 35ab7e7..31fd2b5 100644 --- a/lib/crypto/gpg/gpgbin/sign.go +++ b/lib/crypto/gpg/gpgbin/sign.go @@ -2,6 +2,7 @@ package gpgbin import ( "bytes" + "fmt" "io" "git.sr.ht/~rjarry/aerc/models" @@ -20,7 +21,10 @@ func Sign(r io.Reader, from string) ([]byte, string, error) { outRdr := bytes.NewReader(g.stdout.Bytes()) var md models.MessageDetails - parse(outRdr, &md) + err := parse(outRdr, &md) + if err != nil { + return nil, "", fmt.Errorf("failed to parse messagedetails: %v", err) + } var buf bytes.Buffer io.Copy(&buf, md.Body) return buf.Bytes(), md.Micalg, nil