Skip to content

Commit

Permalink
move: avoid crash when message list is not ready
Browse files Browse the repository at this point in the history
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: 40c25ca ("mv: allow to move messages across accounts")
Link: https://lists.sr.ht/~rjarry/aerc-devel/%[email protected]%3E
Link: https://lists.sr.ht/~rjarry/aerc-devel/%[email protected]%3E
Link: https://lists.sr.ht/~rjarry/aerc-devel/%[email protected]%3E
Reported-by: Alex Freudenberg <[email protected]>
Reported-by: Evin Yulo <[email protected]>
Reported-by: Maarten Aertsen <[email protected]>
Reported-by: Yuri Schaeffer <[email protected]>
Signed-off-by: Robin Jarry <[email protected]>
Acked-by: Tim Culverhouse <[email protected]>
Acked-by: Tristan Partin <[email protected]>
  • Loading branch information
rjarry committed Jun 4, 2024
1 parent 0465509 commit 20c63c6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions commands/msg/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
}
Expand Down

0 comments on commit 20c63c6

Please sign in to comment.