mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
fix nil pointer deref when importing a message that the junkfilter could not parse (e.g. malformed header)
import does its own batched junkfilter training, so the deliver function doesn't have to do it one message at a time, writing the updated filter each time. however, if the message cannot be parsed, it isn't trained during import, and deliver would try to train it again. it would try to open the junk filter to do so, but that would fail because the import function already has the junkfilter open (and the timeout is reached). a missing error check would continue with a nil junkfilter, resulting in the nil pointer deref. this adds the missing error check, and makes sure the deliver function does not also try to train unparseable imported messages. report from Jens Hilligsøe
This commit is contained in:
parent
7e56ed9e8d
commit
9b3a170cc2
2 changed files with 8 additions and 7 deletions
|
@ -671,14 +671,12 @@ func (a *Account) DeliverX(log *mlog.Log, tx *bstore.Tx, m *Message, msgFile *os
|
|||
xcheckf(err, "sync directory")
|
||||
}
|
||||
|
||||
if notrain && m.NeedsTraining() {
|
||||
// If this ever happens, hopefully we'll get bug reports about it.
|
||||
log.Error("deliver of message that unexpectedly needs training", mlog.Field("messageid", m.ID), mlog.Field("trainedjunk", m.TrainedJunk), mlog.Field("flags", m.Flags))
|
||||
if !notrain && m.NeedsTraining() {
|
||||
l := []Message{*m}
|
||||
err = a.RetrainMessages(log, tx, l, false)
|
||||
xcheckf(err, "training junkfilter")
|
||||
*m = l[0]
|
||||
}
|
||||
l := []Message{*m}
|
||||
err = a.RetrainMessages(log, tx, l, false)
|
||||
xcheckf(err, "training junkfilter")
|
||||
*m = l[0]
|
||||
}
|
||||
|
||||
// write contents of r to new file dst, for delivering a message.
|
||||
|
|
|
@ -2,6 +2,7 @@ package store
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -63,6 +64,8 @@ func (a *Account) RetrainMessages(log *mlog.Log, tx *bstore.Tx, msgs []Message,
|
|||
if err != nil && errors.Is(err, ErrNoJunkFilter) {
|
||||
// No junk filter configured. Nothing more to do.
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("open junk filter: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if jf != nil {
|
||||
|
|
Loading…
Reference in a new issue