aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-03-22 00:50:02 +0100
committerRobin Jarry <robin@jarry.cc>2022-03-22 09:45:59 +0100
commit93c160ab66c0ecf6854dfc13ef3ebba26c3aefe8 (patch)
treecf049b5b015e509baad3ad16ccbc2d34ef344ef9 /lib
parent4c699d35f88d50cb7596d421f3c2dab725261c10 (diff)
downloadaerc-93c160ab66c0ecf6854dfc13ef3ebba26c3aefe8.tar.gz
threading: fix stack overflow from faulty headers
Fix stack overflow from faulty headers that cause a circularity in the threading algorithm. Remove duplicated message-ids in the references headers. Check that the message-id itself is not part of the references. Fixes: https://todo.sr.ht/~rjarry/aerc/32 Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Robin Jarry <robin@jarry.cc> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/threadbuilder.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go
index 8ffb7c1f..9137fc17 100644
--- a/lib/threadbuilder.go
+++ b/lib/threadbuilder.go
@@ -200,7 +200,19 @@ func (t *threadable) MessageThreadReferences() []string {
}
refs = []string{inreplyto}
}
- return refs
+ return cleanRefs(t.MessageThreadID(), refs)
+}
+
+func cleanRefs(m string, refs []string) []string {
+ considered := make(map[string]interface{})
+ cleanRefs := make([]string, 0, len(refs))
+ for _, r := range refs {
+ if _, seen := considered[r]; r != m && !seen {
+ considered[r] = nil
+ cleanRefs = append(cleanRefs, r)
+ }
+ }
+ return cleanRefs
}
func (t *threadable) Subject() string {