aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-08-23 11:11:37 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-24 15:49:18 +0200
commit4e950b989e3095794c1e95dee7cb6fb7bb472070 (patch)
treebad952091c2f0f40c32f2755cac458c64575b9bf /worker
parentf07038bd98de5282703cd80c32959e58a47da86b (diff)
downloadaerc-4e950b989e3095794c1e95dee7cb6fb7bb472070.tar.gz
imap: fix SeqMap.Pop runtime error
Fix a runtime error in the SeqMap.Pop function causing a index-out-of-range panic: Version: 0.18.2.r22.gfff69046 (go1.22.6 amd64 linux 2024-08-10) Error: runtime error: index out of range [487] with length 487 goroutine 24430 [running]: runtime/debug.Stack() runtime/debug/stack.go:24 +0x5e git.sr.ht/~rjarry/aerc/lib/log.PanicHandler() git.sr.ht/~rjarry/aerc/lib/log/panic-logger.go:49 +0x66a panic({0x5dbf5a688020?, 0xc002ab0d80?}) runtime/panic.go:770 +0x132 git.sr.ht/~rjarry/aerc/worker/imap.(*SeqMap).Pop(0xc0003d4940, 0x1e8) git.sr.ht/~rjarry/aerc/worker/imap/seqmap.go:64 +0x17c git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleImapUpdate(0xc0003d4820, {0x5dbf5a6dbd00, 0xc002068708}) git.sr.ht/~rjarry/aerc/worker/imap/worker.go:296 +0x26c git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).drainUpdates.func1() git.sr.ht/~rjarry/aerc/worker/imap/flags.go:29 +0x10c created by git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).drainUpdates in goroutine 52 git.sr.ht/~rjarry/aerc/worker/imap/flags.go:21 +0x78 SeqMap.Pop uses two locks in the same function: first lock grabs the size of the slice, second lock removes the given index in the slice. Combine the two locks to prevent a change of the slice size before the index can be removed. Reported-by: Moritz Poldrack <moritz@poldrack.dev> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/seqmap.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/worker/imap/seqmap.go b/worker/imap/seqmap.go
index 4a845865..1e64d377 100644
--- a/worker/imap/seqmap.go
+++ b/worker/imap/seqmap.go
@@ -57,13 +57,13 @@ func (s *SeqMap) Put(uid uint32) {
// Pop removes seqnum from the SeqMap. seqnum must be a valid seqnum, ie
// [1:size of mailbox]
func (s *SeqMap) Pop(seqnum uint32) (uint32, bool) {
- if int(seqnum) > s.Size() || seqnum < 1 {
+ s.lock.Lock()
+ defer s.lock.Unlock()
+ if int(seqnum) > len(s.m) || seqnum < 1 {
return 0, false
}
- s.lock.Lock()
uid := s.m[seqnum-1]
s.m = append(s.m[:seqnum-1], s.m[seqnum:]...)
- s.lock.Unlock()
return uid, true
}