Skip to content

Commit 309e575

Browse files
committed
Added fuzzer
1 parent 0b9986c commit 309e575

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

fuzz.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package redis
2+
3+
import (
4+
"context"
5+
"time"
6+
)
7+
8+
var (
9+
ctx = context.Background()
10+
rdb *Client
11+
)
12+
13+
func init() {
14+
rdb = NewClient(&Options{
15+
Addr: ":6379",
16+
DialTimeout: 10 * time.Second,
17+
ReadTimeout: 10 * time.Second,
18+
WriteTimeout: 10 * time.Second,
19+
PoolSize: 10,
20+
PoolTimeout: 10 * time.Second,
21+
})
22+
}
23+
24+
func Fuzz(data []byte) int {
25+
array_len := len(data)
26+
if array_len < 4 {
27+
return -1
28+
}
29+
max_iter := int(uint(data[0]))
30+
for i := 0; i < max_iter && i < array_len; i++ {
31+
n := i % array_len
32+
if n == 0 {
33+
_ = rdb.Set(ctx, string(data[i:]), string(data[i:]), 0).Err()
34+
} else if n == 1 {
35+
_, _ = rdb.Get(ctx, string(data[i:])).Result()
36+
} else if n == 2 {
37+
_, _ = rdb.Incr(ctx, string(data[i:])).Result()
38+
} else if n == 3 {
39+
var cursor uint64
40+
_, _, _ = rdb.Scan(ctx, cursor, string(data[i:]), 10).Result()
41+
}
42+
}
43+
return 1
44+
}

0 commit comments

Comments
 (0)