view,list: fix crash when viewing incomplete imap messages
With IMAP, due to an unidentified reason, some messages to not have any body accessible. When viewing them, aerc crashes: git.sr.ht/~sircmpwn/aerc/lib.usePGP lib/messageview.go:37 git.sr.ht/~sircmpwn/aerc/lib.NewMessageStoreView lib/messageview.go:67 git.sr.ht/~sircmpwn/aerc/commands/account.ViewMessage.Execute commands/account/view.go:45 git.sr.ht/~sircmpwn/aerc/commands.(*Commands).ExecuteCommand commands/commands.go:66 main.execCommand aerc.go:61 main.main.func2 aerc.go:160 aerc crashed: runtime error: invalid memory address or nil pointer dereference Check the pointer before dereferencing. Also, add a global check in ParseMessageFormat where a similar issue may occur. Signed-off-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
fc84b19bba
commit
074b0a1bd8
|
@ -58,6 +58,10 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
}
|
}
|
||||||
|
|
||||||
envelope := ctx.MsgInfo.Envelope
|
envelope := ctx.MsgInfo.Envelope
|
||||||
|
if envelope == nil {
|
||||||
|
return "", nil,
|
||||||
|
errors.New("no envelope available for this message")
|
||||||
|
}
|
||||||
|
|
||||||
var c rune
|
var c rune
|
||||||
for i, ni := 0, 0; i < len(format); {
|
for i, ni := 0, 0; i < len(format); {
|
||||||
|
@ -105,10 +109,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
case '%':
|
case '%':
|
||||||
retval = append(retval, '%')
|
retval = append(retval, '%')
|
||||||
case 'a':
|
case 'a':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
errors.New("found no address for sender")
|
errors.New("found no address for sender")
|
||||||
|
@ -117,10 +117,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, addr.Address)
|
args = append(args, addr.Address)
|
||||||
case 'A':
|
case 'A':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
var addr *mail.Address
|
var addr *mail.Address
|
||||||
if len(envelope.ReplyTo) == 0 {
|
if len(envelope.ReplyTo) == 0 {
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
|
@ -156,10 +152,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
dummyIfZeroDate(date.Local(),
|
dummyIfZeroDate(date.Local(),
|
||||||
timeFmt, thisDayTimeFmt, thisYearTimeFmt))
|
timeFmt, thisDayTimeFmt, thisYearTimeFmt))
|
||||||
case 'f':
|
case 'f':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
errors.New("found no address for sender")
|
errors.New("found no address for sender")
|
||||||
|
@ -168,10 +160,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, addr)
|
args = append(args, addr)
|
||||||
case 'F':
|
case 'F':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
errors.New("found no address for sender")
|
errors.New("found no address for sender")
|
||||||
|
@ -196,17 +184,9 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
args = append(args, strings.Join(ctx.MsgInfo.Labels, ", "))
|
args = append(args, strings.Join(ctx.MsgInfo.Labels, ", "))
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, envelope.MessageId)
|
args = append(args, envelope.MessageId)
|
||||||
case 'n':
|
case 'n':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
errors.New("found no address for sender")
|
errors.New("found no address for sender")
|
||||||
|
@ -221,33 +201,17 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, val)
|
args = append(args, val)
|
||||||
case 'r':
|
case 'r':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
addrs := FormatAddresses(envelope.To)
|
addrs := FormatAddresses(envelope.To)
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, addrs)
|
args = append(args, addrs)
|
||||||
case 'R':
|
case 'R':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
addrs := FormatAddresses(envelope.Cc)
|
addrs := FormatAddresses(envelope.Cc)
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, addrs)
|
args = append(args, addrs)
|
||||||
case 's':
|
case 's':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, envelope.Subject)
|
args = append(args, envelope.Subject)
|
||||||
case 't':
|
case 't':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
if len(envelope.To) == 0 {
|
if len(envelope.To) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
errors.New("found no address for recipient")
|
errors.New("found no address for recipient")
|
||||||
|
@ -259,10 +223,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, ctx.AccountName)
|
args = append(args, ctx.AccountName)
|
||||||
case 'u':
|
case 'u':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
errors.New("found no address for sender")
|
errors.New("found no address for sender")
|
||||||
|
@ -275,10 +235,6 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
retval = append(retval, 's')
|
retval = append(retval, 's')
|
||||||
args = append(args, mailbox)
|
args = append(args, mailbox)
|
||||||
case 'v':
|
case 'v':
|
||||||
if envelope == nil {
|
|
||||||
return "", nil,
|
|
||||||
errors.New("no envelope available for this message")
|
|
||||||
}
|
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
errors.New("found no address for sender")
|
errors.New("found no address for sender")
|
||||||
|
|
|
@ -34,6 +34,9 @@ type MessageView interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func usePGP(info *models.BodyStructure) bool {
|
func usePGP(info *models.BodyStructure) bool {
|
||||||
|
if info == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if info.MIMEType == "application" {
|
if info.MIMEType == "application" {
|
||||||
if info.MIMESubType == "pgp-encrypted" ||
|
if info.MIMESubType == "pgp-encrypted" ||
|
||||||
info.MIMESubType == "pgp-signature" {
|
info.MIMESubType == "pgp-signature" {
|
||||||
|
|
Loading…
Reference in New Issue