Files
gomail/internal/imap/tokenize_fuzz_test.go
T

34 lines
970 B
Go
Raw Normal View History

2026-08-09 18:03:09 +01:00
package imap
import "testing"
func FuzzTokenize(f *testing.F) {
f.Add(`a001 LOGIN user pass`)
f.Add(`a002 SELECT INBOX`)
f.Add(`a003 FETCH 1:* (FLAGS UID)`)
f.Add(`a004 SEARCH UNSEEN`)
f.Add(`a005 STORE 1 +FLAGS (\Seen)`)
f.Add(`a006 LOGIN "quoted user" "quoted pass"`)
f.Add("")
f.Add(`(((((`)
f.Add(`"unterminated`)
f.Add(`a007 LIST "" *`)
f.Add(`a008 UID FETCH 1 (BODY[HEADER])`)
f.Add(`nested (parens (inside (parens)))`)
f.Add("\x00\x01\x02 binary garbage")
f.Add(`"escaped \" quote"`)
f.Fuzz(func(t *testing.T, data string) {
// tokenize runs on every line a connected IMAP client sends, before
// any authentication has necessarily succeeded (e.g. the initial
// CAPABILITY/LOGIN exchange) — so it's exposed to fully untrusted
// network input and must never panic regardless of what's sent.
defer func() {
if r := recover(); r != nil {
t.Fatalf("tokenize panicked on input %q: %v", data, r)
}
}()
tokenize(data)
})
}