File tree Expand file tree Collapse file tree 1 file changed +58
-1
lines changed Expand file tree Collapse file tree 1 file changed +58
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
package protocol
4
4
5
+ import (
6
+ "bytes"
7
+ "encoding/hex"
8
+ "io"
9
+ "log"
10
+ "strings"
11
+
12
+ "github.com/GopherConRu/pb-fuzz-workshop/kv"
13
+ )
14
+
5
15
func Fuzz (data []byte ) int {
6
- return 0
16
+ kv , err := kv .NewInMemoryBadgerKV ()
17
+ if err != nil {
18
+ panic (err )
19
+ }
20
+ defer func () {
21
+ if err := kv .Close (); err != nil {
22
+ panic (err )
23
+ }
24
+ }()
25
+
26
+ h := NewHandler (kv )
27
+ input , output := h .NewConn ()
28
+
29
+ cmds := strings .Split (string (data ), "\n " )
30
+ cmds = append (cmds , "PING" )
31
+
32
+ readDone := make (chan int )
33
+ go func () {
34
+ b , err := io .ReadAll (output )
35
+ if err != nil {
36
+ panic (err )
37
+ }
38
+
39
+ if ! bytes .HasSuffix (b , []byte ("+PONG\n " )) {
40
+ log .Printf ("Input: %q" , cmds )
41
+ log .Printf ("Output: %q" , strings .Split (string (b ), "\n " ))
42
+ panic ("Raw output:\n " + hex .Dump (b ))
43
+ }
44
+
45
+ if bytes .Contains (b , []byte ("-ERR" )) {
46
+ readDone <- 0
47
+ return
48
+ }
49
+
50
+ readDone <- 1
51
+ }()
52
+
53
+ for _ , cmd := range cmds {
54
+ if _ , err := input .Write ([]byte (cmd + "\n " )); err != nil {
55
+ panic (err )
56
+ }
57
+ }
58
+
59
+ if err := input .Close (); err != nil {
60
+ panic (err )
61
+ }
62
+
63
+ return <- readDone
7
64
}
You can’t perform that action at this time.
0 commit comments