-
Notifications
You must be signed in to change notification settings - Fork 3
/
server_fuzz.go
85 lines (69 loc) · 1.28 KB
/
server_fuzz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// +build gofuzz
package pop3
import (
"io"
"net"
)
var server = &Server{
Auth: &auth{
m: &memoryMaildrop{
messages: map[string]string{
"foo": "first",
"bar": "second",
"foobar": "third",
},
},
},
}
var done = make(chan struct{})
var ln net.Listener
// TODO(dzeromsk): remove tcp/ip stuff
func init() {
var err error
ln, err = net.ListenTCP("tcp", nil)
if err != nil {
panic(err)
}
go func() {
if err := server.Serve(ln); err != nil {
panic(err)
}
close(done)
}()
}
func Fuzz(data []byte) int {
conn, err := net.Dial("tcp", ln.Addr().String())
if err != nil {
return 0
}
defer conn.Close()
_, err = conn.Write(data)
if err != nil {
return 0
}
return 1
}
type auth struct {
m Maildropper
}
func (a *auth) Auth(user, pass string) (Maildropper, error) {
return a.m, nil
}
type memoryMaildrop struct {
messages map[string]string
}
func (m *memoryMaildrop) List() (sizes map[string]int, err error) {
sizes = make(map[string]int)
for k, v := range m.messages {
sizes[k] = len(v)
}
return sizes, nil
}
func (m *memoryMaildrop) Get(key string, message io.Writer) (err error) {
message.Write([]byte(m.messages[key]))
return nil
}
func (m *memoryMaildrop) Delete(key string) (err error) {
delete(m.messages, key)
return nil
}