diff options
author | Robin Jarry <robin@jarry.cc> | 2024-05-29 22:49:53 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-06-04 21:11:16 +0200 |
commit | 20c63c6943ad06989ffa9953534d1c3f2011b18d (patch) | |
tree | 6f085b3d03735aa49862847c865048f4aa6627ed | |
parent | 0465509eedade77954e003a82529435c14cf1f3b (diff) | |
download | aerc-20c63c6943ad06989ffa9953534d1c3f2011b18d.tar.gz |
move: avoid crash when message list is not ready
Fix the following crash:
panic: runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
runtime/panic.go:770 +0x132
git.sr.ht/~rjarry/aerc/lib.(*MessageStore).Selected(...)
git.sr.ht/~rjarry/aerc/lib/msgstore.go:709
git.sr.ht/~rjarry/aerc/commands/msg.Move.CallBack()
git.sr.ht/~rjarry/aerc/commands/msg/move.go:178 +0x78
git.sr.ht/~rjarry/aerc/commands/msg.Move.Execute.func1()
git.sr.ht/~rjarry/aerc/commands/msg/move.go:75 +0x90
git.sr.ht/~rjarry/aerc/lib.(*MessageStore).Move.func1()
git.sr.ht/~rjarry/aerc/lib/msgstore.go:645 +0x138
When a move operation finishes, the callback is invoked but there is no
guarantee that the target account has any message store ready (e.g. IMAP
may be disconnected).
Only access acct.Store() in the happy code path and even there, only use
store if is is not nil.
Fixes: 40c25caafd58 ("mv: allow to move messages across accounts")
Link: https://lists.sr.ht/~rjarry/aerc-devel/%3CD114PEHTFKRE.2R9XF4U2BBDD6@mailbox.org%3E
Link: https://lists.sr.ht/~rjarry/aerc-devel/%3CD118R1N4XZ1X.1ZFQPGG8DSCDA@schaeffer.tk%3E
Link: https://lists.sr.ht/~rjarry/aerc-devel/%3CD1B2PVIVGPOZ.1925R9LL60EAZ@disroot.org%3E
Reported-by: Alex Freudenberg <alexfxd@mailbox.org>
Reported-by: Evin Yulo <yujiri@disroot.org>
Reported-by: Maarten Aertsen <sagi+aerc-devel@rtsn.nl>
Reported-by: Yuri Schaeffer <yuri@schaeffer.tk>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Tristan Partin <tristan@partin.io>
-rw-r--r-- | commands/msg/move.go | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/commands/msg/move.go b/commands/msg/move.go index c073765f..96e7c3da 100644 --- a/commands/msg/move.go +++ b/commands/msg/move.go @@ -192,14 +192,6 @@ func (m Move) CallBack( marker marker.Marker, timeout bool, ) { - store := acct.Store() - sel := store.Selected() - - dest := m.Folder - if len(m.Account) > 0 { - dest = fmt.Sprintf("%s in %s", m.Folder, m.Account) - } - switch msg := msg.(type) { case *types.Done: var s string @@ -208,19 +200,24 @@ func (m Move) CallBack( } else { s = "%d message moved to %s" } + dest := m.Folder + if len(m.Account) > 0 { + dest = fmt.Sprintf("%s in %s", m.Folder, m.Account) + } if timeout { s = "timed-out: only " + s app.PushError(fmt.Sprintf(s, len(uids), dest)) } else { app.PushStatus(fmt.Sprintf(s, len(uids), dest), 10*time.Second) } - handleDone(acct, next, store) + if store := acct.Store(); store != nil { + handleDone(acct, next, store) + } case *types.Error: app.PushError(msg.Error.Error()) marker.Remark() case *types.Unsupported: marker.Remark() - store.Select(sel.Uid) app.PushError("error, unsupported for this worker") } } |