diff options
author | Ensar Sarajčić <dev@ensarsarajcic.com> | 2022-07-22 08:39:39 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-24 23:07:14 +0200 |
commit | 3b90b3b0ddfd8134daa1d417bdd7acd8c39781b7 (patch) | |
tree | a2e2e450e459634ec2b5c1a317d9871b02c9a6a1 | |
parent | ab941ebc6a3707e58aab5986f88c1937389fd859 (diff) | |
download | aerc-3b90b3b0ddfd8134daa1d417bdd7acd8c39781b7.zip |
fix: crash when copying/moving all messages
This prevents dereferencing nil when updating RUE counts. This seems to
happen for messages that were not yet loaded, but were selected for
copy operation. This can happen when using `mark -a` command and then
initiating copy operation.
When such message is encountered during RUE counting, it is stopped
and full recount is triggered.
**Original backtrace:**
Error: runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
runtime/debug.Stack()
runtime/debug/stack.go:24 +0x65
git.sr.ht/~rjarry/aerc/logging.PanicHandler()
git.sr.ht/~rjarry/aerc/logging/panic-logger.go:45 +0x64b
panic({0x9e5f80, 0xecc360})
runtime/panic.go:844 +0x258
git.sr.ht/~rjarry/aerc/widgets.(*AccountView).onMessage(0xc0001be870, {0xb7f860?, 0xc00073b4c0?})
git.sr.ht/~rjarry/aerc/widgets/account.go:353 +0xecc
git.sr.ht/~rjarry/aerc/widgets.(*AccountView).Tick(0xc0001be870)
git.sr.ht/~rjarry/aerc/widgets/account.go:116 +0x6c
git.sr.ht/~rjarry/aerc/widgets.(*Aerc).Tick(0xc0003ba000)
git.sr.ht/~rjarry/aerc/widgets/aerc.go:144 +0x7a
main.main()
git.sr.ht/~rjarry/aerc/aerc.go:225 +0xbb8
Signed-off-by: Ensar Sarajčić <dev@ensarsarajcic.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | widgets/account.go | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/widgets/account.go b/widgets/account.go index 93a277d..3172a30 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -334,12 +334,18 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { // Only update the destination destStore if it is initialized if destStore, ok := acct.dirlist.MsgStore(msg.Destination); ok { var recent, unseen int + var accurate bool = true for _, uid := range msg.Uids { // Get the message from the originating store msg, ok := acct.Store().Messages[uid] if !ok { continue } + // If message that was not yet loaded is copied + if msg == nil { + accurate = false + break + } seen := false for _, flag := range msg.Flags { if flag == models.SeenFlag { @@ -353,13 +359,19 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { unseen = unseen + 1 } } - destStore.DirInfo.Recent += recent - destStore.DirInfo.Unseen += unseen - destStore.DirInfo.Exists += len(msg.Uids) - // True. For imap, we don't have the message in the store until we - // Select so we need to rely on the math we just did for accurate - // counts - destStore.DirInfo.AccurateCounts = true + if accurate { + destStore.DirInfo.Recent += recent + destStore.DirInfo.Unseen += unseen + destStore.DirInfo.Exists += len(msg.Uids) + // True. For imap, we don't have the message in the store until we + // Select so we need to rely on the math we just did for accurate + // counts + destStore.DirInfo.AccurateCounts = true + } else { + destStore.DirInfo.Exists += len(msg.Uids) + // False to trigger recount of recent/unseen + destStore.DirInfo.AccurateCounts = false + } } case *types.LabelList: acct.labels = msg.Labels |