-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathfuzz.go
49 lines (43 loc) · 945 Bytes
/
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
//go:build gofuzz
// +build gofuzz
package fuzz
import (
"context"
"time"
"github.com/redis/go-redis/v9"
)
var (
ctx = context.Background()
rdb *redis.Client
)
func init() {
rdb = redis.NewClient(&redis.Options{
Addr: ":6379",
DialTimeout: 10 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
PoolSize: 10,
PoolTimeout: 10 * time.Second,
})
}
func Fuzz(data []byte) int {
arrayLen := len(data)
if arrayLen < 4 {
return -1
}
maxIter := int(uint(data[0]))
for i := 0; i < maxIter && i < arrayLen; i++ {
n := i % arrayLen
if n == 0 {
_ = rdb.Set(ctx, string(data[i:]), string(data[i:]), 0).Err()
} else if n == 1 {
_, _ = rdb.Get(ctx, string(data[i:])).Result()
} else if n == 2 {
_, _ = rdb.Incr(ctx, string(data[i:])).Result()
} else if n == 3 {
var cursor uint64
_, _, _ = rdb.Scan(ctx, cursor, string(data[i:]), 10).Result()
}
}
return 1
}